Pthreads: Difference between revisions
No edit summary |
|||
| Line 45: | Line 45: | ||
* [[LinuxThreads]] on 2.2+: Same as NPTL, but three signal numbers are consumed. | * [[LinuxThreads]] on 2.2+: Same as NPTL, but three signal numbers are consumed. | ||
* [[LinuxThreads]] before 2.0: SIGUSR1 and SIGUSR2 are used. The program must avoid use of SIGUSR1 and SIGUSR2 in either numeric or symbolic form. | * [[LinuxThreads]] before 2.0: SIGUSR1 and SIGUSR2 are used. The program must avoid use of SIGUSR1 and SIGUSR2 in either numeric or symbolic form. | ||
===[[LinuxThreads]] signals=== | |||
[[LinuxThreads]] (or more accurately, <tt>clone()</tt> prior to the introduction of <tt>CLONE_PID</tt>) failed to guarantee shared PIDs among the threads of a process (each got their own). This severely compromised the POSIX signal model. No concept of process-directed signals exists in [[LinuxThreads]], so external signals are directed to one thread. A "signal manager" thread launched by the library watched for threads terminated due to signal disposition, and attempted to kill the others. Killing the signal management thread was possible, and further broke signal delivery. Signals generated by the terminal, or delivered to the process group, were sent to all threads. | |||
==Compiling code with pthreads== | ==Compiling code with pthreads== | ||
First off, POSIX requires _REENTRANT be defined in the scope of all code run in a multithreaded manner. This is most typically achieved via -D_REENTRANT on the gcc command line. Some gcc versions / target architectures provide a -pthread option which sets -D_REENTRANT (as well as setting up pthread linking), as evidenced below:<pre>Date: Sun, 8 Apr 2007 23:33:23 -0400 | First off, POSIX requires _REENTRANT be defined in the scope of all code run in a multithreaded manner. This is most typically achieved via -D_REENTRANT on the gcc command line. Some gcc versions / target architectures provide a -pthread option which sets -D_REENTRANT (as well as setting up pthread linking), as evidenced below:<pre>Date: Sun, 8 Apr 2007 23:33:23 -0400 | ||