+#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)");
+#endif
+ os_invalidate((os_vm_address_t) th->control_stack_start,
+ ((sizeof (lispobj))
+ * (th->control_stack_end-th->control_stack_start)) +
+ BINDING_STACK_SIZE+ALIEN_STACK_SIZE+dynamic_values_bytes+
+ 32*SIGSTKSZ);
+ return 0;
+ }
+}
+#endif