2 * thread.library - threading and synchronisation primitives
4 * Copyright © 2007 Robert Norris
6 * This program is free software; you can redistribute it and/or modify it
7 * under the same terms as AROS itself.
10 #include "thread_intern.h"
12 #include <proto/exec.h>
15 /*****************************************************************************
18 AROS_LH1(BOOL
, DetachThread
,
21 AROS_LHA(uint32_t, thread_id
, D0
),
24 struct ThreadBase
*, ThreadBase
, 8, Thread
)
27 Detaches a thread from the parent process.
30 thread_id - ID of thread to detach.
33 TRUE if the thread was detached, FALSE if the thread was already
34 detached or another error occured.
37 You cannot detach a thread that is already detached.
39 Once detached, the thread is no longer accessible from any other
46 Currently this doesn't really do anything other than make it so you
47 can't call WaitThread() on the thread. Threads can't truly be detached
48 from the parent process since they run in the same address space, and
49 so when the process exits the program code and all its other resources
52 thread.library protects against this by waiting for all threads to
53 complete (detached or not) before allowing the main process to exit.
55 Detached threads can't be truly implemented until a thread task and its
56 allocated resources can exist independently of the process that created
60 CreateThread(), CurrentThread(), WaitThread(), WaitAllThreads()
64 *****************************************************************************/
71 struct _Thread
*thread
= _getthreadbyid(thread_id
, ThreadBase
);
75 /* mark it detached */
76 ObtainSemaphore(&thread
->lock
);
77 thread
->detached
= TRUE
;
78 ReleaseSemaphore(&thread
->lock
);