2
0

README 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. WELCOME!
  2. The State Threads Library is a small application library which provides
  3. a foundation for writing fast and highly scalable Internet applications
  4. (such as web servers, proxy servers, mail transfer agents, and so on,
  5. really any network-data-driven application) on UNIX-like platforms. It
  6. combines the simplicity of the multithreaded programming paradigm, in
  7. which one thread supports each simultaneous connection, with the
  8. performance and scalability of an event-driven state machine
  9. architecture. In other words, this library offers a threading API for
  10. structuring an Internet application as a state machine. For more
  11. details, please see the library documentation in the "docs" directory or
  12. on-line at
  13. http://state-threads.sourceforge.net/docs/
  14. The State Threads Project is an open source project for maintaining and
  15. enhancing the State Threads Library. For more information about this
  16. project, please see
  17. http://state-threads.sourceforge.net/
  18. BUILDING
  19. To build the library by hand, use the GNU make utility. Run the make
  20. command (e.g., `gmake') with no arguments to display all supported
  21. targets.
  22. To build more or less automatically, first set the CONFIG_GUESS_PATH
  23. variable in either osguess.sh or your environment then run "make
  24. default" which guesses your OS and builds. Requires the "config.guess"
  25. utility from GNU autoconf (not included with ST). You can use one from
  26. a larger "main" software project or just use any config.guess available
  27. on your system. You can also get it directly from GNU:
  28. ftp://ftp.gnu.org/gnu/autoconf/
  29. To build rpms (RedHat Linux 6.2 or later, Linux/Mandrake, Solaris with
  30. gnome, etc.):
  31. download the latest st-x.y.tar.gz
  32. # rpm -ta st-x.y.tar.gz
  33. The .rpms will land in /usr/src/RPMS/<arch>. Install them with:
  34. # rpm -i libst*.rpm
  35. Requires GNU automake and rpm 3.0.3 or later.
  36. Debian users:
  37. If you run potato, please upgrade to woody.
  38. If you run woody, "apt-get install libst-dev" will get you v1.3.
  39. If you run testing/unstable, you will get the newest available version.
  40. If you *must* have the newest libst in woody, you may follow these
  41. not-recommended instructions:
  42. 1. Add "deb-src <your-favourite-debian-mirror> unstable main" to your
  43. /etc/apt/sources.list
  44. 2. apt-get update
  45. 3. apt-get source st
  46. 4. cd st-1.4 (or whatever version you got)
  47. 5. debuild
  48. 6. dpkg -i ../*.deb
  49. If your application uses autoconf to search for dependencies and you
  50. want to search for a given version of libst, you can simply add
  51. PKG_CHECK_MODULES(MYAPP, st >= 1.3 mumble >= 0.2.23)
  52. to your configure.ac/in. This will define @MYAPP_LIBS@ and
  53. @MYAPP_CFLAGS@ which you may then use in your Makefile.am/in files to
  54. link against mumble and st.
  55. LICENSE
  56. The State Threads library is a derivative of the Netscape Portable
  57. Runtime library (NSPR). All source code in this directory is
  58. distributed under the terms of the Mozilla Public License (MPL) version
  59. 1.1 or the GNU General Public License (GPL) version 2 or later. For
  60. more information about these licenses please see
  61. http://www.mozilla.org/MPL/ and http://www.gnu.org/copyleft/.
  62. All source code in the "examples" directory is distributed under the BSD
  63. style license.
  64. PLATFORMS
  65. Please see the "docs/notes.html" file for the list of currently
  66. supported platforms.
  67. DEBUGGER SUPPORT
  68. It's almost impossible to print SP and PC in a portable way. The only
  69. way to see thread's stack platform-independently is to actually jump to
  70. the saved context. That's what the _st_iterate_threads() function does.
  71. Do the following to iterate over all threads:
  72. - set the _st_iterate_threads_flag to 1 in debugger
  73. - set breakpoint at the _st_show_thread_stack() function
  74. (which does nothing)
  75. - call the _st_iterate_threads() function which jumps to the
  76. next thread
  77. - at each break you can explore thread's stack
  78. - continue
  79. - when iteration is complete, you return to the original
  80. point (you can see thread id and a message as arguments of
  81. the _st_show_thread_stack() function).
  82. You can call _st_iterate_threads() in three ways:
  83. - Insert it into your source code at the point you want to
  84. go over threads.
  85. - Just run application and this function will be called at
  86. the first context switch.
  87. - Call it directly from the debugger at any point.
  88. This works with gdb and dbx.
  89. Example using gdb:
  90. (gdb) set _st_iterate_threads_flag = 1
  91. (gdb) b _st_show_thread_stack
  92. ...
  93. (gdb) call _st_iterate_threads()
  94. ...
  95. (gdb) bt
  96. ...
  97. (gdb) c
  98. ...
  99. (gdb) bt
  100. ...
  101. (gdb) c
  102. ...
  103. and so on...
  104. _st_iterate_threads_flag will be set to 0 automatically
  105. after iteration is over or you can set it to 0 at any time
  106. to stop iteration.
  107. Sometimes gdb complains about SIGSEGV when you call a function
  108. directly at gdb command-line. It can be ignored -- just call the
  109. same function right away again, it works just fine. For example:
  110. (gdb) set _st_iterate_threads_flag = 1
  111. (gdb) b _st_show_thread_stack
  112. Breakpoint 1 at 0x809bbbb: file sched.c, line 856.
  113. (gdb) call _st_iterate_threads()
  114. Program received signal SIGSEGV, Segmentation fault.
  115. ....
  116. (gdb) # just call the function again:
  117. (gdb) call _st_iterate_threads()
  118. Breakpoint 1, _st_show_thread_stack (thread=0x4017aee4, messg=0x80ae7a2
  119. "Iteration started") at sched.c:856
  120. 856 }
  121. ....
  122. You can use simple gdb command-line scripting to display
  123. all threads and their stack traces at once:
  124. (gdb) while _st_iterate_threads_flag
  125. >bt
  126. >c
  127. >end
  128. ....
  129. Another script to stop at the thread with the specific thread id
  130. (e.g., 0x40252ee4):
  131. (gdb) # set the flag again:
  132. (gdb) set _st_iterate_threads_flag = 1
  133. (gdb) call _st_iterate_threads()
  134. Breakpoint 1, _st_show_thread_stack (thread=0x4017aee4, messg=0x80ae7a2
  135. "Iteration started") at sched.c:856
  136. 856 }
  137. ....
  138. (gdb) while thread != 0x40252ee4
  139. >c
  140. >end
  141. ....
  142. ....
  143. Breakpoint 1, _st_show_thread_stack (thread=0x40252ee4, messg=0x0) at
  144. sched.c:856
  145. 856 }
  146. (gdb) bt
  147. ....
  148. (gdb) # don't want to continue iteration, unset the flag:
  149. (gdb) set _st_iterate_threads_flag = 0
  150. (gdb) c
  151. Continuing.
  152. Breakpoint 1, _st_show_thread_stack (thread=0x0, messg=0x80ae78e "Iteration
  153. completed")
  154. at sched.c:856
  155. 856 }
  156. (gdb) c
  157. Continuing.
  158. (gdb) return
  159. Make selected stack frame return now? (y or n) y
  160. #0 0x4011254e in __select ()
  161. from /lib/libc.so.6
  162. (gdb) detach
  163. CHANGE LOG
  164. Changes from 1.8 to 1.9.
  165. ------------------------
  166. o Support 32-bit and 64-bit Intel Macs.
  167. o Added ST_VERSION string, and ST_VERSION_MAJOR and ST_VERSION_MINOR
  168. [bug 1796801].
  169. o Fixed some compiler warnings, based on a patch from Brian Wellington
  170. [bug 1932741].
  171. Changes from 1.7 to 1.8.
  172. --------------------------
  173. o Added support for kqueue and epoll on platforms that support them.
  174. Added ability to choose the event notification system at program
  175. startup.
  176. o Long-overdue public definitions of ST_UTIME_NO_TIMEOUT (-1ULL) and
  177. ST_UTIME_NO_WAIT (0) [bug 1514436].
  178. o Documentation patch for st_utime() [bug 1514484].
  179. o Documentation patch for st_timecache_set() [bug 1514486].
  180. o Documentation patch for st_netfd_serialize_accept() [bug 1514494].
  181. o Added st_writev_resid() [rfe 1538344].
  182. o Added st_readv_resid() [rfe 1538768] and, for symmetry, st_readv().
  183. Changes from 1.6 to 1.7.
  184. ------------------------
  185. o Support glibc 2.4, which breaks programs that manipulate jump buffers.
  186. Replaced Linux IA64 special cases with new md.S that covers all
  187. Linux.
  188. Changes from 1.5.2 to 1.6.
  189. --------------------------
  190. none
  191. Changes from 1.5.1 to 1.5.2.
  192. ----------------------------
  193. o Alfred Perlstein's context switch callback feature.
  194. o Claus Assmann's st_recvmsg/st_sendmsg wrappers.
  195. o Extra stack padding for platforms that need it.
  196. o Ron Arts's timeout clarifications in the reference manual.
  197. o Raymond Bero and Anton Berezin's AMD64 FreeBSD port.
  198. o Claus Assmann's AMD64 SunOS 5.10 port.
  199. o Claus Assmann's AMD64 OpenBSD port.
  200. o Michael Abd-El-Malek's Mac OS X port.
  201. o Michael Abd-El-Malek's stack printing patch.
  202. Changes from 1.5.0 to 1.5.1.
  203. ----------------------------
  204. o Andreas Gustafsson's USE_POLL fix.
  205. o Gene's st_set_utime_function() enhancement.
  206. Changes from 1.4 to 1.5.0.
  207. --------------------------
  208. o Andreas Gustafsson's performance patch.
  209. o New extensions: Improved DNS resolver, generic LRU cache, in-process
  210. DNS cache, and a program to test the resolver and cache.
  211. o Support for AMD Opteron 64-bit CPUs under Linux.
  212. o Support for SPARC-64 under Solaris.
  213. o Andreas Gustafsson's support for VAX under NetBSD.
  214. o Changed unportable #warning directives in md.h to #error.
  215. Changes from 1.3 to 1.4.
  216. ------------------------
  217. o Andreas Gustafsson's NetBSD port.
  218. o Wesley W. Terpstra's Darwin (MacOS X) port.
  219. o Support for many CPU architectures under Linux and *BSD.
  220. o Renamed private typedefs so they don't conflict with public ones any
  221. more.
  222. o common.h now includes public.h for strict prototyping.
  223. o Joshua Levy's recommendation to make st_connect() and st_sendto()
  224. accept const struct sockaddr pointers, as the originals do.
  225. o Clarified the documentation regarding blocking vs. non-blocking I/O.
  226. o Cygwin support.
  227. o Created the extensions directory.
  228. o Fixed warnings from ia64asm.S.
  229. Changes from 1.2 to 1.3.
  230. ------------------------
  231. o Added st_read_resid() and st_write_resid() to allow the caller to know
  232. how much data was transferred before an error occurred. Updated
  233. documentation.
  234. o Updated project link, copyrights, and documentation regarding
  235. timeouts. Added comment to st_connect().
  236. o Optimized the _st_add_sleep_q() function in sched.c. Now we walk the
  237. sleep queue *backward* when inserting a thread into it. When you
  238. have lots (hundreds) of threads and several timeout values, it takes
  239. a while to insert a thread at the appropriate point in the sleep
  240. queue. The idea is that often this appropriate point is closer to
  241. the end of the queue rather than the beginning. Measurements show
  242. performance improves with this change. In any case this change
  243. should do no harm.
  244. o Added a hint of when to define USE_POLL and when not to, to the
  245. Makefile.
  246. o Added debugging support (files common.h and sched.c). See above.
  247. o Decreased the number of reallocations of _ST_POLLFDS in sched.c.
  248. Inspired by Lev Walkin.
  249. o Fixed st_usleep(-1) and st_sleep(-1), and added a warning to the
  250. documentation about too-large timeouts.
  251. o Linux/*BSD Alpha port.
  252. o Wesley W. Terpstra modernized the build process:
  253. - properly build relocatable libraries under bsd and linux
  254. - use library versioning
  255. - added rpm spec file
  256. - added debian/ files
  257. See above for build instructions.
  258. Changes from 1.1 to 1.2.
  259. ------------------------
  260. o Added st_randomize_stacks().
  261. o Added a patch contributed by Sascha Schumann.
  262. Changes from 1.0 to 1.1.
  263. ------------------------
  264. o Relicensed under dual MPL-GPL.
  265. o OpenBSD port.
  266. o Compile-time option to use poll() instead of select() for
  267. event polling (see Makefile).
  268. This is useful if you want to support a large number of open
  269. file descriptors (larger than FD_SETSIZE) within a single
  270. process.
  271. o Linux IA-64 port.
  272. Two issues make IA-64 different from other platforms:
  273. - Besides the traditional call stack in memory, IA-64 uses the
  274. general register stack. Thus each thread needs a backing store
  275. for the register stack in addition to the memory stack.
  276. - Current implementation of setjmp()/longjmp() can not be used
  277. for thread context-switching since it assumes that only one
  278. register stack exists. Using special assembly functions for
  279. context-switching is unavoidable.
  280. o Thread stack capping on IRIX.
  281. This allows some profiling tools (such as SpeedShop) to know when
  282. to stop unwinding the stack. Without this libexc, used by SpeedShop,
  283. traces right off the stack and crashes.
  284. o Miscellaneous documentation additions.
  285. COPYRIGHTS
  286. Portions created by SGI are Copyright (C) 2000 Silicon Graphics, Inc.
  287. All Rights Reserved.