1 #ifndef __lib_base_thread_h
2 #define __lib_base_thread_h
6 #include <lib/base/elock.h>
8 /* the following states are possible:
9 1 thread has not yet started
10 2 thread has started, but not completed initialization (hadStarted not yet called)
12 4 thread has finished, but not yet joined
13 5 thread has joined (same as state 1)
16 0 (="not alive") for 1, 4, 5
19 it will wait when state is 2. It can't differentiate between
20 state 3 and 4, because a thread could always finish.
22 all other state transitions (1 -> 2, 4 -> 5) must be activately
23 changed by either calling run() or kill().
32 /* runAsync starts the thread.
33 it assumes that the thread is not running,
34 i.e. sync() *must* return 0.
35 it will not wait for anything. */
36 int runAsync(int prio=0, int policy=0);
38 /* run will wait until the thread has either
39 passed it's initialization, or it has
41 int run(int prio=0, int policy=0);
43 virtual void thread()=0;
45 /* waits until thread is in "run" state */
46 /* result: 0 - thread is not alive
47 1 - thread state unknown */
49 void sendSignal(int sig);
51 /* join the thread, i.e. busywait until thread has finnished. */
52 void kill(bool sendcancel=false);
56 static void *wrapper(void *ptr);
58 static void thread_completed(void *p);