-void destroy_thread (struct thread *th)
-{
- /* precondition: the unix task has already been killed and exited.
- * This is called by the parent */
-#ifdef LISP_FEATURE_GENCGC
- gc_alloc_update_page_tables(0, &th->alloc_region);
+void create_initial_thread(lispobj initial_function) {
+ struct thread *th=create_thread_struct(initial_function);
+ pid_t kid_pid=getpid();
+ if(th && kid_pid>0) {
+ link_thread(th,kid_pid);
+ initial_thread_trampoline(all_threads); /* no return */
+ } else lose("can't create initial thread");
+}
+
+#ifdef LISP_FEATURE_SB_THREAD
+pid_t create_thread(lispobj initial_function) {
+ struct thread *th;
+ pid_t kid_pid=0;
+
+ if(linux_no_threads_p) return 0;
+ th=create_thread_struct(initial_function);
+ if(th==0) return 0;
+#ifdef QSHOW_SIGNALS
+ SHOW("create_thread:waiting on lock");
+#endif
+ get_spinlock(&thread_start_lock,arch_os_get_current_thread()->pid);
+#ifdef QSHOW_SIGNALS
+ SHOW("create_thread:got lock");
+#endif
+ kid_pid=clone(new_thread_trampoline,
+ (((void*)th->control_stack_start)+
+ THREAD_CONTROL_STACK_SIZE-16),
+ CLONE_FILES|SIG_THREAD_EXIT|CLONE_VM,th);
+
+ if(kid_pid>0) {
+ link_thread(th,kid_pid);
+ /* wait here until our thread is started: see new_thread_trampoline */
+ while(th->state==STATE_STARTING) sched_yield();
+ /* it's started and initialized, it's safe to gc */
+ release_spinlock(&thread_start_lock);
+#ifdef QSHOW_SIGNALS
+ SHOW("create_thread:released lock");
+#endif
+ return th->pid;
+ } else {
+ release_spinlock(&thread_start_lock);
+#ifdef QSHOW_SIGNALS
+ SHOW("create_thread:released lock(failure)");