README 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. Linuxthreads - POSIX 1003.1c kernel threads for Linux
  2. Copyright 1996, 1997 Xavier Leroy (Xavier.Leroy@inria.fr)
  3. DESCRIPTION:
  4. This is release 0.7 (late beta) of LinuxThreads, a BiCapitalized
  5. implementation of the Posix 1003.1c "pthread" interface for Linux.
  6. LinuxThreads provides kernel-level threads: each thread is a separate
  7. Unix process, sharing its address space with the other threads through
  8. the new system call clone(). Scheduling between threads is handled by
  9. the kernel scheduler, just like scheduling between Unix processes.
  10. REQUIREMENTS:
  11. - Linux version 2.0 and up (requires the new clone() system call
  12. and the new realtime scheduler).
  13. - For Intel platforms: libc 5.2.18 or later is required.
  14. 5.2.18 or 5.4.12 or later are recommended;
  15. 5.3.12 and 5.4.7 have problems (see the FAQ.html file for more info).
  16. - Also supports glibc 2 (a.k.a. libc 6), which actually comes with
  17. a specially-adapted version of this library.
  18. - Currently supports Intel, Alpha, Sparc, Motorola 68k, ARM and MIPS
  19. platforms.
  20. - Multiprocessors are supported.
  21. INSTALLATION:
  22. - Edit the Makefile, set the variables in the "Configuration" section.
  23. - Do "make".
  24. - Do "make install".
  25. USING LINUXTHREADS:
  26. gcc -D_REENTRANT ... -lpthread
  27. A complete set of manual pages is included. Also see the subdirectory
  28. Examples/ for some sample programs.
  29. STATUS:
  30. - All functions in the Posix 1003.1c base interface implemented.
  31. Also supports priority scheduling.
  32. - For users of libc 5 (H.J.Lu's libc), a number of C library functions
  33. are reimplemented or wrapped to make them thread-safe, including:
  34. * malloc functions
  35. * stdio functions (define _REENTRANT before including <stdio.h>)
  36. * per-thread errno variable (define _REENTRANT before including <errno.h>)
  37. * directory reading functions (opendir(), etc)
  38. * sleep()
  39. * gmtime(), localtime()
  40. New library functions provided:
  41. * flockfile(), funlockfile(), ftrylockfile()
  42. * reentrant versions of network database functions (gethostbyname_r(), etc)
  43. and password functions (getpwnam_r(), etc).
  44. - libc 6 (glibc 2) provides much better thread support than libc 5,
  45. and comes with a specially-adapted version of LinuxThreads.
  46. For serious multithreaded programming, you should consider switching
  47. to glibc 2. It is available from ftp.gnu.org:/pub/gnu and its mirrors.
  48. WARNING:
  49. Many existing libraries are not compatible with LinuxThreads,
  50. either because they are not inherently thread-safe, or because they
  51. have not been compiled with the -D_REENTRANT. For more info, see the
  52. FAQ.html file in this directory.
  53. A prime example of the latter is Xlib. If you link it with
  54. LinuxThreads, you'll probably get an "unknown 0 error" very
  55. early. This is just a consequence of the Xlib binaries using the
  56. global variable "errno" to fetch error codes, while LinuxThreads and
  57. the C library use the per-thread "errno" location.
  58. See the file README.Xfree3.3 for info on how to compile the Xfree 3.3
  59. libraries to make them compatible with LinuxThreads.
  60. KNOWN BUGS AND LIMITATIONS:
  61. - Threads share pretty much everything they should share according
  62. to the standard: memory space, file descriptors, signal handlers,
  63. current working directory, etc. One thing that they do not share
  64. is their pid's and parent pid's. According to the standard, they
  65. should have the same, but that's one thing we cannot achieve
  66. in this implementation (until the CLONE_PID flag to clone() becomes
  67. usable).
  68. - The current implementation uses the two signals SIGUSR1 and SIGUSR2,
  69. so user-level code cannot employ them. Ideally, there should be two
  70. signals reserved for this library. One signal is used for restarting
  71. threads blocked on mutexes or conditions; the other is for thread
  72. cancellation.
  73. *** This is not anymore true when the application runs on a kernel
  74. newer than approximately 2.1.60.
  75. - The stacks for the threads are allocated high in the memory space,
  76. below the stack of the initial process, and spaced 2M apart.
  77. Stacks are allocated with the "grow on demand" flag, so they don't
  78. use much virtual space initially (4k, currently), but can grow
  79. up to 2M if needed.
  80. Reserving such a large address space for each thread means that,
  81. on a 32-bit architecture, no more than about 1000 threads can
  82. coexist (assuming a 2Gb address space for user processes),
  83. but this is reasonable, since each thread uses up one entry in the
  84. kernel's process table, which is usually limited to 512 processes.
  85. Another potential problem of the "grow on demand" scheme is that
  86. nothing prevents the user from mmap'ing something in the 2M address
  87. window reserved for a thread stack, possibly causing later extensions of
  88. that stack to fail. Mapping at fixed addresses should be avoided
  89. when using this library.
  90. - Signal handling does not fully conform to the Posix standard,
  91. due to the fact that threads are here distinct processes that can be
  92. sent signals individually, so there's no notion of sending a signal
  93. to "the" process (the collection of all threads).
  94. More precisely, here is a summary of the standard requirements
  95. and how they are met by the implementation:
  96. 1- Synchronous signals (generated by the thread execution, e.g. SIGFPE)
  97. are delivered to the thread that raised them.
  98. (OK.)
  99. 2- A fatal asynchronous signal terminates all threads in the process.
  100. (OK. The thread manager notices when a thread dies on a signal
  101. and kills all other threads with the same signal.)
  102. 3- An asynchronous signal will be delivered to one of the threads
  103. of the program which does not block the signal (it is unspecified
  104. which).
  105. (No, the signal is delivered to the thread it's been sent to,
  106. based on the pid of the thread. If that thread is currently
  107. blocking the signal, the signal remains pending.)
  108. 4- The signal will be delivered to at most one thread.
  109. (OK, except for signals generated from the terminal or sent to
  110. the process group, which will be delivered to all threads.)
  111. - The current implementation of the MIPS support assumes a MIPS ISA II
  112. processor or better. These processors support atomic operations by
  113. ll/sc instructions. Older R2000/R3000 series processors are not
  114. supported yet; support for these will have higher overhead.
  115. - The current implementation of the ARM support assumes that the SWP
  116. (atomic swap register with memory) instruction is available. This is
  117. the case for all processors except for the ARM1 and ARM2. On StrongARM,
  118. the SWP instruction does not bypass the cache, so multi-processor support
  119. will be more troublesome.