• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // RUN: %clang_cl_asan -O0 %s -Fe%t
2 // RUN: %run %t
3 
4 #include <windows.h>
5 
thread_proc(void *)6 DWORD WINAPI thread_proc(void *) {
7   volatile char stack_buffer[42];
8   for (int i = 0; i < sizeof(stack_buffer); ++i)
9     stack_buffer[i] = 42;
10   return 0;
11 }
12 
main(void)13 int main(void) {
14   for (int iter = 0; iter < 1024; ++iter) {
15     const int NUM_THREADS = 8;
16     HANDLE thr[NUM_THREADS];
17     for (int i = 0; i < NUM_THREADS; ++i) {
18       thr[i] = CreateThread(NULL, 0, thread_proc, NULL, 0, NULL);
19       if (thr[i] == 0)
20         return 1;
21     }
22     for (int i = 0; i < NUM_THREADS; ++i) {
23       if (WAIT_OBJECT_0 != WaitForSingleObject(thr[i], INFINITE))
24         return 2;
25       CloseHandle(thr[i]);
26     }
27   }
28   return 0;
29 }
30 
31