19
19
What follows, is a short description on my implementation of TThread.
20
20
Most information can also be found by reading the source and accompanying
23
23
A thread is created using BeginThread, which in turn calls
24
24
pthread_create. So the threads here are always posix threads.
25
25
Posix doesn't define anything for suspending threads as this is
26
26
inherintly unsafe. Just don't suspend threads at points they cannot
27
27
control. Therefore, I didn't implement .Suspend() if its called from
28
28
outside the threads execution flow (except on Linux _without_ NPTL).
30
30
The implementation for .suspend uses a semaphore, which is initialized
31
31
at thread creation. If the thread tries to suspend itself, we simply
32
32
let it wait on the semaphore until it is unblocked by someone else
38
38
1) the system has the LinuxThreads pthread implementation
39
39
2) the system has NPTL as the pthread implementation.
41
41
In the first case, each thread is a process on its own, which as far as
42
42
know actually violates posix with respect to signal handling.
43
43
But we can detect this case, because getpid(2) will
48
48
PID across all threads, which is detected, and TThread.Suspend() does
49
49
nothing in that case. This should probably be changed, but I know of
50
50
no way to suspend a thread when using NPTL.
52
52
If the symbol LINUX is not defined, then the unimplemented
53
53
function SuspendThread is called.
55
55
Johannes Berg <johannes@sipsolutions.de>, Sunday, November 16 2003
134
133
if LThread.FInitialSuspended then begin
135
134
SemaphoreWait(LThread.FSem);
136
if not LThread.FInitialSuspended then begin
135
if not LThread.FSuspended then begin
136
LThread.FInitialSuspended := false;
137
137
WRITE_DEBUG('going into LThread.Execute');
293
288
$Log: tthread.inc,v $
294
Revision 1.3 2004/03/04 12:42:44 jonas
295
- removed legacy code
297
Revision 1.2 2004/03/04 12:34:36 jonas
300
Revision 1.1 2004/01/04 20:05:38 jonas
301
* first working version of the Darwin/Mac OS X (for PowerPC) RTL
302
Several non-essential units are still missing, but make cycle works
304
Revision 1.7 2003/11/22 11:04:08 marco
305
* Johill: suspend fix
307
Revision 1.6 2003/11/19 10:12:02 marco
310
Revision 1.5 2003/11/17 10:05:51 marco
311
* threads for FreeBSD. Not working tho
313
Revision 1.4 2003/11/17 08:27:49 marco
314
* pthreads based ttread from Johannes Berg
316
Revision 1.3 2003/11/10 16:54:28 marco
317
* new oldlinux unit. 1_0 defines killed in some former FCL parts.
319
Revision 1.2 2003/11/03 09:42:28 marco
320
* Peter's Cardinal<->Longint fixes patch
322
Revision 1.1 2003/10/06 21:01:06 peter
323
* moved classes unit to rtl
325
Revision 1.9 2003/10/06 17:06:55 florian
326
* applied Johannes Berg's patch for exception handling in threads
328
Revision 1.8 2003/09/20 15:10:30 marco
329
* small fixes. fcl now compiles
331
Revision 1.7 2002/12/18 20:44:36 peter
332
* use fillchar to clear sigset
334
Revision 1.6 2002/09/07 15:15:27 peter
335
* old logs removed and tabs fixed
289
Revision 1.7 2005/03/25 22:53:39 jonas
290
* fixed several warnings and notes about unused variables (mainly) or
291
uninitialised use of variables/function results (a few)
293
Revision 1.6 2005/03/01 20:38:49 jonas
294
* fixed web bug 3387: if one called resume right after creating a
295
suspended thread, it was possible that resume was executed before
296
that thread had completed its initialisation in BeginThread ->
297
FInitialSuspended was set to false in resume and nevertheless a
299
* second problem fixed: set FSuspended to false before waking up the
300
thread, so that it doesn't get FSuspended = true right after waking
301
up. This should be done atomically to be completely correct though.
303
Revision 1.5 2005/02/25 21:41:09 florian
304
* generic tthread.synchronize
305
* delphi compatible wakemainthread
307
Revision 1.4 2005/02/14 17:13:22 peter