github.com/golang/gofrontend@v0.0.0-20240429183944-60f985a78526/libgo/misc/cgo/test/cthread_windows.c (about) 1 // Copyright 2013 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 #define WIN32_LEAN_AND_MEAN 6 #include <windows.h> 7 #include <process.h> 8 #include "_cgo_export.h" 9 10 __stdcall 11 static unsigned int 12 addThread(void *p) 13 { 14 int i, max; 15 16 max = *(int*)p; 17 for(i=0; i<max; i++) 18 Add(i); 19 return 0; 20 } 21 22 void 23 doAdd(int max, int nthread) 24 { 25 enum { MaxThread = 20 }; 26 int i; 27 uintptr_t thread_id[MaxThread]; 28 29 if(nthread > MaxThread) 30 nthread = MaxThread; 31 for(i=0; i<nthread; i++) 32 thread_id[i] = _beginthreadex(0, 0, addThread, &max, 0, 0); 33 for(i=0; i<nthread; i++) { 34 WaitForSingleObject((HANDLE)thread_id[i], INFINITE); 35 CloseHandle((HANDLE)thread_id[i]); 36 } 37 }