Exemple #1
0
void
mono_threads_init (MonoThreadInfoCallbacks *callbacks, size_t info_size)
{
	gboolean res;
	threads_callbacks = *callbacks;
	thread_info_size = info_size;
#ifdef HOST_WIN32
	res = mono_native_tls_alloc (&thread_info_key, NULL);
#else
	res = mono_native_tls_alloc (&thread_info_key, unregister_thread);
#endif
	g_assert (res);

	res = mono_native_tls_alloc (&small_id_key, NULL);
	g_assert (res);

	MONO_SEM_INIT (&global_suspend_semaphore, 1);

	mono_lls_init (&thread_list, NULL);
	mono_thread_smr_init ();
	mono_threads_init_platform ();

#if defined(__MACH__)
	mono_mach_init (thread_info_key);
#endif

	mono_threads_inited = TRUE;

	g_assert (sizeof (MonoNativeThreadId) <= sizeof (uintptr_t));
}
Exemple #2
0
void
mono_threads_init (MonoThreadInfoCallbacks *callbacks, size_t info_size)
{
	gboolean res;
	threads_callbacks = *callbacks;
	thread_info_size = info_size;
#ifdef HOST_WIN32
	res = mono_native_tls_alloc (&thread_info_key, NULL);
#else
	res = mono_native_tls_alloc (&thread_info_key, unregister_thread);
#endif
	g_assert (res);

	res = mono_native_tls_alloc (&small_id_key, NULL);
	g_assert (res);

	InitializeCriticalSection (&global_suspend_lock);

	mono_lls_init (&thread_list, NULL);
	mono_thread_smr_init ();
	mono_threads_init_platform ();

	mono_threads_inited = TRUE;

	g_assert (sizeof (MonoNativeThreadId) <= sizeof (uintptr_t));
}
Exemple #3
0
void
mono_threads_init (MonoThreadInfoCallbacks *callbacks, size_t info_size)
{
	gboolean res;
	threads_callbacks = *callbacks;
	thread_info_size = info_size;
	const char *sleepLimit;
#ifdef HOST_WIN32
	res = mono_native_tls_alloc (&thread_info_key, NULL);
	res = mono_native_tls_alloc (&thread_exited_key, NULL);
#else
	res = mono_native_tls_alloc (&thread_info_key, (void *) thread_info_key_dtor);
	res = mono_native_tls_alloc (&thread_exited_key, (void *) thread_exited_dtor);
#endif

	g_assert (res);

#ifndef HAVE_KW_THREAD
	res = mono_native_tls_alloc (&small_id_key, NULL);
#endif
	g_assert (res);

	unified_suspend_enabled = g_getenv ("MONO_ENABLE_UNIFIED_SUSPEND") != NULL || mono_threads_is_coop_enabled ();
	
	if ((sleepLimit = g_getenv ("MONO_SLEEP_ABORT_LIMIT")) != NULL) {
		errno = 0;
		long threshold = strtol(sleepLimit, NULL, 10);
		if ((errno == 0) && (threshold >= 40))  {
			sleepAbortDuration = threshold;
			sleepWarnDuration = threshold / 20;
		} else
			g_warning("MONO_SLEEP_ABORT_LIMIT must be a number >= 40");
	}

	mono_os_sem_init (&global_suspend_semaphore, 1);
	mono_os_sem_init (&suspend_semaphore, 0);

	mono_lls_init (&thread_list, NULL, HAZARD_FREE_NO_LOCK);
	mono_thread_smr_init ();
	mono_threads_platform_init ();
	mono_threads_suspend_init ();
	mono_threads_coop_init ();
	mono_threads_abort_syscall_init ();

#if defined(__MACH__)
	mono_mach_init (thread_info_key);
#endif

	mono_threads_inited = TRUE;

	g_assert (sizeof (MonoNativeThreadId) <= sizeof (uintptr_t));
}
Exemple #4
0
void
mono_threads_init (MonoThreadInfoCallbacks *callbacks, size_t info_size)
{
	gboolean res;
	threads_callbacks = *callbacks;
	thread_info_size = info_size;
#ifdef HOST_WIN32
	res = mono_native_tls_alloc (&thread_info_key, NULL);
	res = mono_native_tls_alloc (&thread_exited_key, NULL);
#else
	res = mono_native_tls_alloc (&thread_info_key, (void *) unregister_thread);
	res = mono_native_tls_alloc (&thread_exited_key, (void *) thread_exited_dtor);
#endif

	g_assert (res);

#ifndef HAVE_KW_THREAD
	res = mono_native_tls_alloc (&small_id_key, NULL);
#endif
	g_assert (res);

	unified_suspend_enabled = g_getenv ("MONO_ENABLE_UNIFIED_SUSPEND") != NULL || mono_threads_is_coop_enabled ();

	mono_coop_sem_init (&global_suspend_semaphore, 1);
	mono_os_sem_init (&suspend_semaphore, 0);

	mono_lls_init (&thread_list, NULL);
	mono_thread_smr_init ();
	mono_threads_init_platform ();
	mono_threads_init_coop ();
	mono_threads_init_abort_syscall ();

#if defined(__MACH__)
	mono_mach_init (thread_info_key);
#endif

	mono_threads_inited = TRUE;

	g_assert (sizeof (MonoNativeThreadId) <= sizeof (uintptr_t));
}
int
main (int argc, char *argv [])
{
	int primes [] = { 1, 2, 3, 5, 7, 11, 13, 17 };
	MonoThreadInfoCallbacks thread_callbacks;
	thread_data_t thread_data [NUM_THREADS];
	int i;

	memset (&thread_callbacks, 0, sizeof (thread_callbacks));

	mono_metadata_init ();

	mono_threads_init (&thread_callbacks, 0);

	mono_thread_smr_init ();
	mono_lls_init (&lls, free_node);

	for (i = 0; i < N; ++i) {
		nodes [i].node.key = i;
		nodes [i].state = STATE_OUT;
	}

	for (i = 0; i < NUM_THREADS; ++i) {
		int result;

		thread_data [i].num_adds = thread_data [i].num_removes = 0;
		thread_data [i].skip = primes [i];
		result = pthread_create (&thread_data [i].thread, NULL, worker, &thread_data [i]);
		assert (!result);
	}

	for (i = 0; i < NUM_THREADS; ++i) {
		int result = pthread_join (thread_data [i].thread, NULL);
		assert (!result);
		printf ("thread %d  adds %d  removes %d\n", i, thread_data [i].num_adds, thread_data [i].num_removes);
	}

	return 0;
}