+/**
+ * Provides a startup wrapper for each thread, allowing some initial
+ * model-checking data to be recorded. This method also gets around makecontext
+ * not being 64-bit clean
+ */
+void thread_startup()
+{
+ Thread * curr_thread = thread_current();
+
+ /* Add dummy "start" action, just to create a first clock vector */
+ model->switch_to_master(new ModelAction(THREAD_START, std::memory_order_seq_cst, curr_thread));
+
+ /* Call the actual thread function */
+ if (curr_thread->start_routine != NULL) {
+ curr_thread->start_routine(curr_thread->arg);
+ } else if (curr_thread->pstart_routine != NULL) {
+ // set pthread return value
+ void *retval = curr_thread->pstart_routine(curr_thread->arg);
+ curr_thread->set_pthread_return(retval);
+ }
+ /* Finish thread properly */
+ model->switch_to_master(new ModelAction(THREAD_FINISH, std::memory_order_seq_cst, curr_thread));
+}
+
+/**
+ * Create a thread context for a new thread so we can use
+ * setcontext/getcontext/swapcontext to swap it out.
+ * @return 0 on success; otherwise, non-zero error condition
+ */