[Date Prev][Date Next] [Chronological] [Thread] [Top]

Do not use _beginthread() (ITS#872)



Full_Name: Jerzy Wirecki
Version: 2.0.6
OS: NT 4.0
URL: ftp://ftp.openldap.org/incoming/
Submission from: (NULL) (135.90.24.1)


In NT port of slapd, the code uses _beginthread() to spawn threads.
This is incorrect, since thread handles returned by _beginthread()
cannot be waited for with WaitForSingleObject().

Here is a suggested modification of ldap_pvt_thread_create() in
thr_nt.c module:
==================================================================
int 
ldap_pvt_thread_create( ldap_pvt_thread_t * thread, 
	int detach,
	void *(*start_routine)( void *),
	void *arg)
{
	/*
	*thread = (ldap_pvt_thread_t)_beginthread( (void *) start_routine, 
						0, arg );
	return ( (unsigned long)*thread == -1 ? -1 : 0 );
	*/

	unsigned long tid;
	HANDLE thd;

	thd = _beginthreadex(NULL, 0, (LPTHREAD_START_ROUTINE)start_routine, arg, 0,
&tid);
	*thread = (ldap_pvt_thread_t)thd;
	return (thd == NULL ? -1 : 0);
}