2 * Copyright (C) 2011 Ludovic Courtes
4 * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
5 * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
7 * Permission is hereby granted to use or copy this program
8 * for any purpose, provided the above notices are retained on all copies.
9 * Permission to modify the code and to distribute modified code is granted,
10 * provided the above notices are retained, and a notice that the code was
11 * modified is included with the above copyright notice.
14 /* Make sure 'GC_INIT' can be called from threads other than the initial
26 #define GC_NO_THREAD_REDIRECTS 1
27 /* Do not redirect thread creation and join calls. */
41 static void *thread(void *arg
)
43 static DWORD WINAPI
thread(LPVOID arg
)
48 (void)GC_MALLOC(12345);
52 return (DWORD
)(GC_word
)arg
;
56 #include "private/gcconfig.h"
67 # if !(defined(BEOS) || defined(MSWIN32) || defined(MSWINCE) \
68 || defined(CYGWIN32) || defined(GC_OPENBSD_THREADS) \
69 || (defined(DARWIN) && !defined(NO_PTHREAD_GET_STACKADDR_NP)) \
70 || (defined(LINUX) && !defined(NACL)) \
71 || (defined(GC_SOLARIS_THREADS) && !defined(_STRICT_STDC)) \
72 || (!defined(STACKBOTTOM) && (defined(HEURISTIC1) \
73 || (!defined(LINUX_STACKBOTTOM) && !defined(FREEBSD_STACKBOTTOM)))))
74 /* GC_INIT() must be called from main thread only. */
78 if ((code
= pthread_create (&t
, NULL
, thread
, NULL
)) != 0) {
79 fprintf(stderr
, "Thread creation failed %d\n", code
);
82 if ((code
= pthread_join (t
, NULL
)) != 0) {
83 fprintf(stderr
, "Thread join failed %d\n", code
);
87 t
= CreateThread(NULL
, 0, thread
, 0, 0, &thread_id
);
89 fprintf(stderr
, "Thread creation failed %d\n", (int)GetLastError());
92 if (WaitForSingleObject(t
, INFINITE
) != WAIT_OBJECT_0
) {
93 fprintf(stderr
, "Thread join failed %d\n", (int)GetLastError());