Exemplo n.º 1
0
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
		   LPWSTR lpCmdLine, int nShowCmd)
{
    DWORD exit_code = 1;

    main_thread_args args = {
	hInstance, hPrevInstance, lpCmdLine, nShowCmd
    };
    HANDLE thread_h;
    DWORD thread_id;

    /* initialize everything */
    GC_init();

    /* start the main thread */
    thread_h = GC_CreateThread(
	NULL, 0, main_thread_start, &args, 0, &thread_id);

    if (thread_h != NULL)
    {
	WaitForSingleObject (thread_h, INFINITE);
	GetExitCodeThread (thread_h, &exit_code);
	CloseHandle (thread_h);
    }

    GC_deinit();
    DeleteCriticalSection(&GC_allocate_ml);

    return (int) exit_code;
}
Exemplo n.º 2
0
EXTERN int neko_thread_create( thread_main_func init, thread_main_func main, void *param, void **handle ) {
	tparams p;
	p.init = init;
	p.main = main;
	p.param = param;
#	if !defined(NEKO_THREADS)
	return 0;
#	elif defined(NEKO_WINDOWS)
	{
		HANDLE h;
		p.lock = CreateSemaphore(NULL,0,1,NULL);
		h = GC_CreateThread(NULL,0,ThreadMain,&p,0,(void*)handle);
		if( h == NULL ) {
			CloseHandle(p.lock);
			return 0;
		}
		WaitForSingleObject(p.lock,INFINITE);
		CloseHandle(p.lock);
		CloseHandle(h);
		return 1;
	}
#	else
	pthread_mutex_init(&p.lock,NULL);
	pthread_mutex_lock(&p.lock);
	// force the use of a the GC method to capture created threads
	// this function should be defined in gc/gc.h
	if( GC_pthread_create((pthread_t*)handle,NULL,&ThreadMain,&p) != 0 ) {
		pthread_mutex_destroy(&p.lock);
		return 0;
	}
	pthread_mutex_lock(&p.lock);
	pthread_mutex_destroy(&p.lock);
	return 1;
#	endif
}
Exemplo n.º 3
0
void create_profiler_thread(LPTHREAD_START_ROUTINE start)
{
  DWORD id;
  HANDLE h = GC_CreateThread(NULL, // default security descriptor
                             0,    // default stack size
                             start,
                             NULL,
                             0,    // default creation flags
                             &id);
  if (!h)
    signal_lisp_error("Unable to create profiler thread.");
}
Exemplo n.º 4
0
 void fork_a_thread(void)
 {
     DWORD thread_id;
     HANDLE h;
     h = GC_CreateThread(NULL, 0, tiny_reverse_test, 0, 0, &thread_id);
     if (h == (HANDLE)NULL) {
         GC_printf("Small thread creation failed %d\n",
                       (int)GetLastError());
         FAIL;
     }
     if (WaitForSingleObject(h, INFINITE) != WAIT_OBJECT_0) {
         GC_printf("Small thread wait failed %d\n",
                       (int)GetLastError());
         FAIL;
     }
 }