summaryrefslogtreecommitdiff
path: root/lib/libpthread/uthread/uthread_create.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libpthread/uthread/uthread_create.c')
-rw-r--r--lib/libpthread/uthread/uthread_create.c21
1 files changed, 19 insertions, 2 deletions
diff --git a/lib/libpthread/uthread/uthread_create.c b/lib/libpthread/uthread/uthread_create.c
index 53759d8f440..68db603cac2 100644
--- a/lib/libpthread/uthread/uthread_create.c
+++ b/lib/libpthread/uthread/uthread_create.c
@@ -44,9 +44,9 @@ int
pthread_create(pthread_t * thread, const pthread_attr_t * attr,
void *(*start_routine) (void *), void *arg)
{
- int i;
+ int f_gc = 0;
int ret = 0;
- int status;
+ pthread_t gc_thread;
pthread_t new_thread;
pthread_attr_t pattr;
void *stack;
@@ -149,6 +149,12 @@ pthread_create(pthread_t * thread, const pthread_attr_t * attr,
/* Lock the thread list: */
_lock_thread_list();
+ /*
+ * Check if the garbage collector thread
+ * needs to be started.
+ */
+ f_gc = (_thread_link_list == _thread_initial);
+
/* Add the thread to the linked list of all threads: */
new_thread->nxt = _thread_link_list;
_thread_link_list = new_thread;
@@ -161,6 +167,14 @@ pthread_create(pthread_t * thread, const pthread_attr_t * attr,
/* Schedule the new user thread: */
_thread_kern_sched(NULL);
+
+ /*
+ * Start a garbage collector thread
+ * if necessary.
+ */
+ if (f_gc && pthread_create(&gc_thread,NULL,
+ _thread_gc,NULL) != 0)
+ PANIC("Can't create gc thread");
}
}
@@ -171,6 +185,9 @@ pthread_create(pthread_t * thread, const pthread_attr_t * attr,
void
_thread_start(void)
{
+ /* We just left the scheduler via longjmp: */
+ _thread_kern_in_sched = 0;
+
/* Run the current thread's start routine with argument: */
pthread_exit(_thread_run->start_routine(_thread_run->arg));