1 /* Creating and controlling threads (native Windows implementation). 2 Copyright (C) 2005-2021 Free Software Foundation, Inc. 3 4 This file is free software: you can redistribute it and/or modify 5 it under the terms of the GNU Lesser General Public License as 6 published by the Free Software Foundation; either version 2.1 of the 7 License, or (at your option) any later version. 8 9 This file is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU Lesser General Public License for more details. 13 14 You should have received a copy of the GNU Lesser General Public License 15 along with this program. If not, see <https://www.gnu.org/licenses/>. */ 16 17 /* Written by Bruno Haible <bruno@clisp.org>, 2005. 18 Based on GCC's gthr-win32.h. */ 19 20 #ifndef _WINDOWS_THREAD_H 21 #define _WINDOWS_THREAD_H 22 23 #define WIN32_LEAN_AND_MEAN /* avoid including junk */ 24 #include <windows.h> 25 26 /* The glwthread_thread_t is a pointer to a structure in memory. 27 Why not the thread handle? If it were the thread handle, it would be hard 28 to implement glwthread_thread_self() (since GetCurrentThread () returns a 29 pseudo-handle, DuplicateHandle (GetCurrentThread ()) returns a handle that 30 must be closed afterwards, and there is no function for quickly retrieving 31 a thread handle from its id). 32 Why not the thread id? I tried it. It did not work: Sometimes ids appeared 33 that did not belong to running threads, and glthread_join failed with ESRCH. 34 */ 35 typedef struct glwthread_thread_struct *glwthread_thread_t; 36 37 #ifdef __cplusplus 38 extern "C" { 39 #endif 40 41 /* attr is a bit mask, consisting of the following bits: */ 42 #define GLWTHREAD_ATTR_DETACHED 1 43 extern int glwthread_thread_create (glwthread_thread_t *threadp, 44 unsigned int attr, 45 void * (*func) (void *), void *arg); 46 extern int glwthread_thread_join (glwthread_thread_t thread, void **retvalp); 47 extern int glwthread_thread_detach (glwthread_thread_t thread); 48 extern glwthread_thread_t glwthread_thread_self (void); 49 extern _Noreturn void glwthread_thread_exit (void *retval); 50 51 #ifdef __cplusplus 52 } 53 #endif 54 55 #endif /* _WINDOWS_THREAD_H */