int main(void) { int i; # ifdef GC_PTHREADS pthread_t t[NTHREADS]; # else HANDLE t[NTHREADS]; DWORD thread_id; # endif int code; GC_set_find_leak(1); /* for new collect versions not compiled */ /* with -DFIND_LEAK. */ GC_INIT(); for (i = 0; i < NTHREADS; ++i) { # ifdef GC_PTHREADS code = pthread_create(t + i, 0, test, 0); # else t[i] = CreateThread(NULL, 0, test, 0, 0, &thread_id); code = t[i] != NULL ? 0 : (int)GetLastError(); # endif if (code != 0) { fprintf(stderr, "Thread creation failed %d\n", code); exit(2); } } for (i = 0; i < NTHREADS; ++i) { # ifdef GC_PTHREADS code = pthread_join(t[i], 0); # else code = WaitForSingleObject(t[i], INFINITE) == WAIT_OBJECT_0 ? 0 : (int)GetLastError(); # endif if (code != 0) { fprintf(stderr, "Thread join failed %d\n", code); exit(2); } } CHECK_LEAKS(); CHECK_LEAKS(); CHECK_LEAKS(); return 0; }
int APIENTRY WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR command_line, int nCmdShow) { MSG msg; WNDCLASS wndclass; HACCEL hAccel; GC_set_find_leak(0); GC_INIT(); # ifndef NO_INCREMENTAL GC_enable_incremental(); # endif # if defined(CPPCHECK) GC_noop1((GC_word)&WinMain); # endif if (!hPrevInstance) { wndclass.style = CS_HREDRAW | CS_VREDRAW; wndclass.lpfnWndProc = WndProc; wndclass.cbClsExtra = 0; wndclass.cbWndExtra = DLGWINDOWEXTRA; wndclass.hInstance = hInstance; wndclass.hIcon = LoadIcon (hInstance, szAppName); wndclass.hCursor = LoadCursor (NULL, IDC_ARROW); wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wndclass.lpszMenuName = TEXT("DE"); wndclass.lpszClassName = szAppName; if (RegisterClass (&wndclass) == 0) { de_error("RegisterClass error"); return(0); } } /* Empirically, the command line does not include the command name ... if (command_line != 0) { while (isspace(*command_line)) command_line++; while (*command_line != 0 && !isspace(*command_line)) command_line++; while (isspace(*command_line)) command_line++; } */ if (command_line == 0 || *command_line == 0) { de_error("File name argument required"); return( 0 ); } else { char *p = command_line; while (*p != 0 && !isspace(*(unsigned char *)p)) p++; arg_file_name = CORD_to_char_star( CORD_substr(command_line, 0, p - command_line)); } hwnd = CreateWindow (szAppName, TEXT("Demonstration Editor"), WS_OVERLAPPEDWINDOW | WS_CAPTION, /* Window style */ CW_USEDEFAULT, 0, /* default pos. */ CW_USEDEFAULT, 0, /* default width, height */ NULL, /* No parent */ NULL, /* Window class menu */ hInstance, NULL); if (hwnd == NULL) { de_error("CreateWindow error"); return(0); } ShowWindow (hwnd, nCmdShow); hAccel = LoadAccelerators( hInstance, szAppName ); while (GetMessage (&msg, NULL, 0, 0)) { if( !TranslateAccelerator( hwnd, hAccel, &msg ) ) { TranslateMessage (&msg); DispatchMessage (&msg); } } return (int)msg.wParam; }