Use _beginthread() and _endthread() in favor of CreateThread() and
ExitThread(). As discussed in c.l.p, this takes care of initialization and finalization of thread-local storage allocated by the C runtime system. Not sure whether non-MS compilers grok this though (but who cares :-).
This commit is contained in:
parent
d47a0a86b4
commit
49b1226781
|
@ -31,8 +31,9 @@ PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
/* This code implemented by Dag.Gruneau@elsa.preseco.comm.se */
|
/* This code implemented by Dag.Gruneau@elsa.preseco.comm.se */
|
||||||
|
|
||||||
#include "windows.h"
|
#include <windows.h>
|
||||||
#include "limits.h"
|
#include <limits.h>
|
||||||
|
#include <process.h>
|
||||||
|
|
||||||
long get_thread_ident(void);
|
long get_thread_ident(void);
|
||||||
|
|
||||||
|
@ -53,25 +54,16 @@ static void _init_thread(void)
|
||||||
*/
|
*/
|
||||||
int start_new_thread(void (*func)(void *), void *arg)
|
int start_new_thread(void (*func)(void *), void *arg)
|
||||||
{
|
{
|
||||||
HANDLE aThread;
|
long rv;
|
||||||
DWORD aThreadId;
|
int success = 0;
|
||||||
|
|
||||||
int success = 0; /* init not needed when SOLARIS_THREADS and */
|
|
||||||
/* C_THREADS implemented properly */
|
|
||||||
dprintf(("%ld: start_new_thread called\n", get_thread_ident()));
|
dprintf(("%ld: start_new_thread called\n", get_thread_ident()));
|
||||||
if (!initialized)
|
if (!initialized)
|
||||||
init_thread();
|
init_thread();
|
||||||
|
|
||||||
aThread = CreateThread(
|
rv = _beginthread(func, 0, arg); /* use default stack size */
|
||||||
NULL, /* No security attributes */
|
|
||||||
0, /* use default stack size */
|
|
||||||
(LPTHREAD_START_ROUTINE) func, /* thread function */
|
|
||||||
(LPVOID) arg, /* argument to thread function */
|
|
||||||
0, /* use the default creation flags */
|
|
||||||
&aThreadId); /* returns the thread identifier */
|
|
||||||
|
|
||||||
if (aThread != NULL) {
|
if (rv != -1) {
|
||||||
CloseHandle(aThread); /* We do not want to have any zombies hanging around */
|
|
||||||
success = 1;
|
success = 1;
|
||||||
dprintf(("%ld: start_new_thread succeeded: %ld\n", get_thread_ident(), aThreadId));
|
dprintf(("%ld: start_new_thread succeeded: %ld\n", get_thread_ident(), aThreadId));
|
||||||
}
|
}
|
||||||
|
@ -99,7 +91,7 @@ static void do_exit_thread(int no_cleanup)
|
||||||
_exit(0);
|
_exit(0);
|
||||||
else
|
else
|
||||||
exit(0);
|
exit(0);
|
||||||
ExitThread(0);
|
_endthread();
|
||||||
}
|
}
|
||||||
|
|
||||||
void exit_thread(void)
|
void exit_thread(void)
|
||||||
|
|
Loading…
Reference in New Issue