Example #1
0
/*
 * mono_threads_create_thread:
 *
 *   Create a new thread executing START with argument ARG. Store its id into OUT_TID.
 * Returns: a windows or io-layer handle for the thread.
 */
HANDLE
mono_threads_create_thread (MonoThreadStart start, gpointer arg, gsize * const stack_size, MonoNativeThreadId *out_tid)
{
	CreateThreadData *thread_data;
	gint res;
	gpointer ret;

	thread_data = g_new0 (CreateThreadData, 1);
	thread_data->ref = 2;
	thread_data->start_routine = start;
	thread_data->start_routine_arg = arg;
	mono_coop_sem_init (&thread_data->registered, 0);

	res = mono_threads_platform_create_thread (inner_start_thread, (gpointer) thread_data, stack_size, out_tid);
	if (res != 0) {
		/* ref is not going to be decremented in inner_start_thread */
		InterlockedDecrement (&thread_data->ref);
		ret = NULL;
		goto done;
	}

	res = mono_coop_sem_wait (&thread_data->registered, MONO_SEM_FLAGS_NONE);
	g_assert (res == 0);

	ret = thread_data->handle;
	g_assert (ret);

done:
	if (InterlockedDecrement (&thread_data->ref) == 0) {
		mono_coop_sem_destroy (&thread_data->registered);
		g_free (thread_data);
	}

	return ret;
}
Example #2
0
/*
 * mono_threads_create_thread:
 *
 *   Create a new thread executing START with argument ARG. Store its id into OUT_TID.
 * Returns: a windows or io-layer handle for the thread.
 */
MonoThreadHandle*
mono_threads_create_thread (MonoThreadStart start, gpointer arg, gsize * const stack_size, MonoNativeThreadId *out_tid)
{
	CreateThreadData *thread_data;
	gint res;
	MonoThreadHandle *ret;

	thread_data = g_new0 (CreateThreadData, 1);
	mono_refcount_init (thread_data, create_thread_data_destroy);
	thread_data->start_routine = start;
	thread_data->start_routine_arg = arg;
	mono_coop_sem_init (&thread_data->registered, 0);

	res = mono_threads_platform_create_thread (inner_start_thread, (gpointer) mono_refcount_inc (thread_data), stack_size, out_tid);
	if (res != 0) {
		/* ref is not going to be decremented in inner_start_thread */
		mono_refcount_dec (thread_data);
		ret = NULL;
		goto done;
	}

	res = mono_coop_sem_wait (&thread_data->registered, MONO_SEM_FLAGS_NONE);
	g_assert (res == 0);

	ret = thread_data->handle;
	g_assert (ret);

done:
	mono_refcount_dec (thread_data);

	return ret;
}
Example #3
0
/*
 * mono_threads_create_thread:
 *
 *   Create a new thread executing START with argument ARG. Store its id into OUT_TID.
 * Returns: a windows or io-layer handle for the thread.
 */
HANDLE
mono_threads_create_thread (MonoThreadStart start, gpointer arg, MonoThreadParm *tp, MonoNativeThreadId *out_tid)
{
	return mono_threads_platform_create_thread (start, arg, tp, out_tid);
}