home *** CD-ROM | disk | FTP | other *** search
/ Game Programming - All in One (3rd Edition) / game_prog_all_in_one_3rd_ed.iso / pthread / docs / README < prev    next >
Encoding:
Text File  |  2003-09-16  |  14.4 KB  |  459 lines

  1. PTHREADS-WIN32
  2. ==============
  3.  
  4. Pthreads-win32 is free software, distributed under the GNU Lesser
  5. General Public License (LGPL). See the file 'COPYING.LIB' for terms
  6. and conditions. Also see the file 'COPYING' for information
  7. specific to pthreads-win32, copyrights and the LGPL.
  8.  
  9.  
  10. What is it?
  11. -----------
  12.  
  13. Pthreads-win32 is an Open Source Software implementation of the
  14. Threads component of the POSIX 1003.1c 1995 Standard (or later)
  15. for Microsoft's Win32 environment. Some functions from POSIX
  16. 1003.1b are also supported including semaphores. Other related
  17. functions include the set of read-write lock functions. The
  18. library also supports some of the functionality of the Open
  19. Group's Single Unix specification, version 2, namely mutex types,
  20. plus some common and pthreads-win32 specific non-portable
  21. routines (see README.NONPORTABLE).
  22.  
  23. See the file "ANNOUNCE" for more information including standards
  24. conformance details and the list of supported and unsupported
  25. routines.
  26.  
  27.  
  28. Library naming
  29. --------------
  30.  
  31. Because the library is being built using various exception
  32. handling schemes and compilers - and because the library
  33. may not work reliably if these are mixed in an application,
  34. each different version of the library has it's own name.
  35.  
  36. Note 1: the incompatibility is really between EH implementations
  37. of the different compilers. It should be possible to use the
  38. standard C version from either compiler with C++ applications
  39. built with a different compiler. If you use an EH version of
  40. the library, then you must use the same compiler for the
  41. application. This is another complication and dependency that
  42. can be avoided by using only the standard C library version.
  43.  
  44. Note 2: if you use a standard C pthread*.dll with a C++
  45. application, then any functions that you define that are
  46. intended to be called via pthread_cleanup_push() must be
  47. __cdecl.
  48.  
  49. Note 3: the intention is to also name either the VC or GC
  50. version (it should be arbitrary) as pthread.dll, including
  51. pthread.lib and libpthread.a as appropriate.
  52.  
  53. In general:
  54.     pthread[VG]{SE,CE,C}.dll
  55.     pthread[VG]{SE,CE,C}.lib
  56.  
  57. where:
  58.     [VG] indicates the compiler
  59.     V    - MS VC
  60.     G    - GNU C
  61.  
  62.     {SE,CE,C} indicates the exception handling scheme
  63.     SE    - Structured EH
  64.     CE    - C++ EH
  65.     C    - no exceptions - uses setjmp/longjmp
  66.  
  67. For example:
  68.     pthreadVSE.dll    (MSVC/SEH)
  69.     pthreadGCE.dll    (GNUC/C++ EH)
  70.     pthreadGC.dll    (GNUC/not dependent on exceptions)
  71.  
  72. The GNU library archive file names have changed to:
  73.  
  74.     libpthreadGCE.a
  75.     libpthreadGC.a
  76.  
  77.  
  78. Which of the several dll versions to use?
  79. -----------------------------------------
  80. or,
  81. ---
  82. What are all these pthread*.dll and pthread*.lib files?
  83. -------------------------------------------------------
  84.  
  85. Simple, use either pthreadGC.* if you use GCC, or pthreadVC.* if you
  86. use MSVC.
  87.  
  88. Otherwise, you need to choose carefully and know WHY.
  89.  
  90. The most important choice you need to make is whether to use a
  91. version that uses exceptions internally, or not. There are versions
  92. of the library that use exceptions as part of the thread
  93. cancelation and exit implementation. The default version uses
  94. setjmp/longjmp.
  95.  
  96. There is some contension amongst POSIX threads experts as
  97. to how POSIX threads cancelation and exit should work
  98. with languages that use exceptions, e.g. C++ and even C
  99. (Microsoft's Structured Exceptions).
  100.  
  101. The issue is: should cancelation of a thread in, say,
  102. a C++ application cause object destructors and C++ exception
  103. handlers to be invoked as the stack unwinds during thread
  104. exit, or not?
  105.  
  106. There seems to be more opinion in favour of using the
  107. standard C version of the library (no EH) with C++ applications
  108. for the reason that this appears to be the assumption commercial
  109. pthreads implementations make. Therefore, if you use an EH version
  110. of pthreads-win32 then you may be under the illusion that
  111. your application will be portable, when in fact it is likely to
  112. behave differently when linked with other pthreads libraries.
  113.  
  114. Now you may be asking: then why have you kept the EH versions of
  115. the library?
  116.  
  117. There are a couple of reasons:
  118. - there is division amongst the experts and so the code may
  119.   be needed in the future. Yes, it's in the repository and we
  120.   can get it out anytime in the future, but it would be difficult
  121.   to find.
  122. - pthreads-win32 is one of the few implementations, and possibly
  123.   the only freely available one, that has EH versions. It may be
  124.   useful to people who want to play with or study application
  125.   behaviour under these conditions.
  126.  
  127. Notes:
  128.  
  129. [If you use either pthreadVCE or pthreadGCE]
  130.  
  131. 1. [See also the discussion in the FAQ file - Q2, Q4, and Q5]
  132.  
  133. If your application contains catch(...) blocks in your POSIX
  134. threads then you will need to replace the "catch(...)" with the macro
  135. "PtW32Catch", eg.
  136.  
  137.     #ifdef PtW32Catch
  138.         PtW32Catch {
  139.             ...
  140.         }
  141.     #else
  142.         catch(...) {
  143.             ...
  144.         }
  145.     #endif
  146.  
  147. Otherwise neither pthreads cancelation nor pthread_exit() will work
  148. reliably when using versions of the library that use C++ exceptions
  149. for cancelation and thread exit.
  150.  
  151. This is due to what is believed to be a C++ compliance error in VC++
  152. whereby you may not have multiple handlers for the same exception in
  153. the same try/catch block. GNU G++ doesn't have this restriction.
  154.  
  155.  
  156. Other name changes
  157. ------------------
  158.  
  159. All snapshots prior to and including snapshot 2000-08-13
  160. used "_pthread_" as the prefix to library internal
  161. functions, and "_PTHREAD_" to many library internal
  162. macros. These have now been changed to "ptw32_" and "PTW32_"
  163. respectively so as to not conflict with the ANSI standard's
  164. reservation of identifiers beginning with "_" and "__" for
  165. use by compiler implementations only.
  166.  
  167. If you have written any applications and you are linking
  168. statically with the pthreads-win32 library then you may have
  169. included a call to _pthread_processInitialize. You will
  170. now have to change that to ptw32_processInitialize.
  171.  
  172.  
  173. Cleanup code default style
  174. --------------------------
  175.  
  176. Previously, if not defined, the cleanup style was determined automatically
  177. from the compiler used, and one of the following was defined accordingly:
  178.  
  179.     __CLEANUP_SEH    MSVC only
  180.     __CLEANUP_CXX    C++, including MSVC++, GNU G++
  181.     __CLEANUP_C    C, including GNU GCC, not MSVC
  182.  
  183. These defines determine the style of cleanup (see pthread.h) and,
  184. most importantly, the way that cancelation and thread exit (via
  185. pthread_exit) is performed (see the routine ptw32_throw() in private.c).
  186.  
  187. In short, the exceptions versions of the library throw an exception
  188. when a thread is canceled or exits (via pthread_exit()), which is
  189. caught by a handler in the thread startup routine, so that the
  190. the correct stack unwinding occurs regardless of where the thread
  191. is when it's canceled or exits via pthread_exit().
  192.  
  193. In this snapshot, unless the build explicitly defines (e.g. via a
  194. compiler option) __CLEANUP_SEH, __CLEANUP_CXX, or __CLEANUP_C, then
  195. the build NOW always defaults to __CLEANUP_C style cleanup. This style
  196. uses setjmp/longjmp in the cancelation and pthread_exit implementations,
  197. and therefore won't do stack unwinding even when linked to applications
  198. that have it (e.g. C++ apps). This is for consistency with most/all
  199. commercial Unix POSIX threads implementations.
  200.  
  201. Although it was not clearly documented before, it is still necessary to
  202. build your application using the same __CLEANUP_* define as was
  203. used for the version of the library that you link with, so that the
  204. correct parts of pthread.h are included. That is, the possible
  205. defines require the following library versions:
  206.  
  207.     __CLEANUP_SEH    pthreadVSE.dll
  208.     __CLEANUP_CXX    pthreadVCE.dll or pthreadGCE.dll
  209.     __CLEANUP_C    pthreadVC.dll or pthreadGC.dll
  210.  
  211. THE POINT OF ALL THIS IS: if you have not been defining one of these
  212. explicitly, then the defaults as described at the top of this
  213. section were being used.
  214.  
  215. THIS NOW CHANGES, as has been explained above, but to try to make this
  216. clearer here's an example:
  217.  
  218. If you were building your application with MSVC++ i.e. using C++
  219. exceptions (rather than SEH) and not explicitly defining one of
  220. __CLEANUP_*, then __CLEANUP_C++ was defined for you in pthread.h.
  221. You should have been linking with pthreadVCE.dll, which does
  222. stack unwinding.
  223.  
  224. If you now build your application as you had before, pthread.h will now
  225. set __CLEANUP_C as the default style, and you will need to link
  226. with pthreadVC.dll. Stack unwinding will now NOT occur when a thread
  227. is canceled, or the thread calls pthread_exit().
  228.  
  229. Your application will now most likely behave differently to previous
  230. versions, and in non-obvious ways. Most likely is that locally
  231. instantiated objects may not be destroyed or cleaned up after a thread
  232. is canceled.
  233.  
  234. If you want the same behaviour as before, then you must now define
  235. __CLEANUP_C++ explicitly using a compiler option and link with
  236. pthreadVCE.dll as you did before.
  237.  
  238.  
  239. WHY ARE WE MAKING THE DEFAULT STYLE LESS EXCEPTION-FRIENDLY?
  240. Because no commercial Unix POSIX threads implementation allows you to
  241. choose to have stack unwinding. Therefore, providing it in pthread-win32
  242. as a default is dangerous. We still provide the choice but unless
  243. you consciously choose to do otherwise, your pthreads applications will
  244. now run or crash in similar ways irrespective of the threads platform
  245. you use. Or at least this is the hope.
  246.  
  247.  
  248.  
  249. Building under VC++ using C++ EH, Structured EH, or just C
  250. ----------------------------------------------------------
  251.  
  252. From the source directory run one of the following:
  253.  
  254. nmake clean VC    (builds the VC setjmp/longjmp version of pthreadVC.dll)
  255.  
  256. or:
  257.  
  258. nmake clean VCE (builds the VC++ C++ EH version pthreadVCE.dll)
  259.  
  260. or:
  261.  
  262. nmake clean VSE (builds the VC++ structured EH version pthreadVSE.dll)
  263.  
  264. You can run the testsuite by changing to the "tests" directory and
  265. running the target corresponding to the DLL version you built:
  266.  
  267. nmake clean VC
  268.  
  269. or:
  270.  
  271. nmake clean VCE
  272.  
  273. or:
  274.  
  275. nmake clean VSE
  276.  
  277. or:
  278.  
  279. nmake clean VCX (tests the VC version of the library with C++ (EH)
  280.              applications)
  281.  
  282.  
  283. Building under Mingw32
  284. ----------------------
  285.  
  286. The dll can be built easily with recent versions of Mingw32.
  287. (The distributed versions are built using Mingw32 and MsysDTK
  288. from www.mingw32.org.)
  289.  
  290. From the source directory, run
  291.  
  292. make clean GC
  293.  
  294. or:
  295.  
  296. make clean GCE
  297.  
  298. You can run the testsuite by changing to the "tests" directory and
  299. running
  300.  
  301. make clean GC
  302.  
  303. or:
  304.  
  305. make clean GCE
  306.  
  307. or:
  308.  
  309. make clean GCX    (tests the GC version of the library with C++ (EH)
  310.              applications)
  311.  
  312.  
  313. Building the library under Cygwin
  314. ---------------------------------
  315.  
  316. Not tested by me although I think some people have done this.
  317. Not sure how successfully though.
  318.  
  319. Cygwin is implementing it's own POSIX threads routines and these
  320. will be the ones to use if you develop using Cygwin.
  321.  
  322.  
  323. Ready to run binaries
  324. ---------------------
  325.  
  326. For convenience, the following ready-to-run files can be downloaded
  327. from the FTP site (see under "Availability" below):
  328.  
  329.     pthread.h
  330.     semaphore.h
  331.     sched.h
  332.     pthread.def
  333.     pthreadVC.dll    - built with MSVC compiler using C setjmp/longjmp
  334.     pthreadVC.lib
  335.     pthreadVCE.dll    - built with MSVC++ compiler using C++ EH
  336.     pthreadVCE.lib
  337.     pthreadVSE.dll    - built with MSVC compiler using SEH
  338.     pthreadVSE.lib
  339.     pthreadGC.dll    - built with Mingw32 GCC
  340.     libpthreadGC.a    - derived from pthreadGC.dll
  341.     pthreadGCE.dll    - built with Mingw32 G++
  342.     libpthreadGCE.a    - derived from pthreadGCE.dll
  343.  
  344. As of August 2003 pthreads-win32 pthreadG* versions are built and tested
  345. using the MinGW + MsysDTK environment current as of that date or later.
  346. The following file MAY be needed for older MinGW environments.
  347.  
  348.     gcc.dll     - needed to build and run applications that use
  349.               pthreadGCE.dll.
  350.  
  351.  
  352. Building applications with GNU compilers
  353. ----------------------------------------
  354.  
  355. If you're using pthreadGC.dll:
  356.  
  357. With the three header files, pthreadGC.dll and libpthreadGC.a in the
  358. same directory as your application myapp.c, you could compile, link
  359. and run myapp.c under Mingw32 as follows:
  360.  
  361.     gcc -o myapp.exe myapp.c -I. -L. -lpthreadGC
  362.     myapp
  363.  
  364. Or put pthreadGC.dll in an appropriate directory in your PATH,
  365. put libpthreadGC.a in your system lib directory, and
  366. put the three header files in your system include directory,
  367. then use:
  368.  
  369.     gcc -o myapp.exe myapp.c -lpthreadGC
  370.     myapp
  371.  
  372.  
  373. If you're using pthreadGCE.dll:
  374.  
  375. With the three header files, pthreadGCE.dll, gcc.dll and libpthreadGCE.a
  376. in the same directory as your application myapp.c, you could compile,
  377. link and run myapp.c under Mingw32 as follows:
  378.  
  379.     gcc -x c++ -o myapp.exe myapp.c -I. -L. -lpthreadGCE
  380.     myapp
  381.  
  382. Or put pthreadGCE.dll and gcc.dll in an appropriate directory in
  383. your PATH, put libpthreadGCE.a in your system lib directory, and
  384. put the three header files in your system include directory,
  385. then use:
  386.  
  387.     gcc -x c++ -o myapp.exe myapp.c -lpthreadGCE
  388.     myapp
  389.  
  390.  
  391. Availability
  392. ------------
  393.  
  394. The complete source code in either unbundled, self-extracting
  395. Zip file, or tar/gzipped format can be found at:
  396.  
  397.     ftp://sources.redhat.com/pub/pthreads-win32
  398.  
  399. The pre-built DLL, export libraries and matching pthread.h can
  400. be found at:
  401.  
  402.     ftp://sources.redhat.com/pub/pthreads-win32/dll-latest
  403.  
  404. Home page:
  405.  
  406.     http://sources.redhat.com/pthreads-win32/
  407.  
  408.  
  409. Mailing list
  410. ------------
  411.  
  412. There is a mailing list for discussing pthreads on Win32.
  413. To join, send email to:
  414.  
  415.     pthreads-win32-subscribe@sources.redhat.com
  416.  
  417. Unsubscribe by sending mail to:
  418.  
  419.     pthreads-win32-unsubscribe@sources.redhat.com
  420.  
  421.  
  422. Acknowledgements
  423. ----------------
  424.  
  425. Pthreads-win32 is based substantially on a Win32 Pthreads
  426. implementation contributed by John E. Bossom.
  427.  
  428. Many others have contributed important new code,
  429. improvements and bug fixes. Thanks go to Alexander Terekhov
  430. and Louis Thomas for their implementation of condition variables
  431. (see README.CV).
  432.  
  433. Thanks also to the authors of the following paper, which served as
  434. the first CV design, and which identifies the important issues:
  435. "Strategies for Implementing POSIX Condition Variables on Win32"
  436. - http://www.cs.wustl.edu/~schmidt/win32-cv-1.html
  437.  
  438. See the 'CONTRIBUTORS' file for the list of contributors.
  439.  
  440. As much as possible, the ChangeLog file attributes
  441. contributions and patches that have been incorporated
  442. in the library to the individuals responsible.
  443.  
  444. Finally, thanks to all those who work on and contribute to the
  445. POSIX and Single Unix Specification standards. The maturity of an
  446. industry can be measured by it's open standards.
  447.  
  448. ----
  449. Ross Johnson
  450. <rpj@callisto.canberra.edu.au>
  451.  
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459.