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