Martin Sebor
Thu, 26 Jul 2007 11:15:05 -0700
[EMAIL PROTECTED] wrote:
Author: faridz Date: Thu Jul 26 10:23:23 2007 New Revision: 559890 URL: http://svn.apache.org/viewvc?view=rev&rev=559890 Log: 2007-07-26 Farid Zaripov <[EMAIL PROTECTED]> * thread.cpp (rw_thread_create) [_WIN32]: Use _beginthreadex() instead of CreateThread().
What are the advantages of calling _beginthreadex() instead of CreateThread? I ask because I thought that _beginthreadex() was implemented in terms of CreateThread(). Martin
Modified: incubator/stdcxx/trunk/tests/src/thread.cpp Modified: incubator/stdcxx/trunk/tests/src/thread.cpp URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/tests/src/thread.cpp?view=diff&rev=559890&r1=559889&r2=559890 ============================================================================== --- incubator/stdcxx/trunk/tests/src/thread.cpp (original) +++ incubator/stdcxx/trunk/tests/src/thread.cpp Thu Jul 26 10:23:23 2007 @@ -36,8 +36,6 @@ #ifndef _WIN32 # include <stdio.h> // for FILE, fscanf(), popen() # include <unistd.h> // for sysconf(), _SC_NPROCESSORS_{CONF,ONLN} -#else // _WIN32 -# include <windows.h> // for GetSystemInfo() #endif // _WIN32/**************************************************************************/@@ -241,7 +239,8 @@ /**************************************************************************/#elif defined (_WIN32) || defined (_WIN64)-# include <windows.h> +# include <windows.h> // for GetSystemInfo() +# include <process.h> // for _beginthreadex()extern "C" { @@ -258,34 +257,33 @@if (0 == thr_id) thr_id = &tmpid;- DWORD nid; // numerical id- - typedef DWORD ThreadProc (LPVOID); + unsigned nid; // numerical id- LPTHREAD_START_ROUTINE win32_thr_proc =- _RWSTD_REINTERPRET_CAST (LPTHREAD_START_ROUTINE, thr_proc); + typedef unsigned int (__stdcall *win32_thr_proc_t)(void *); + win32_thr_proc_t win32_thr_proc = + _RWSTD_REINTERPRET_CAST (win32_thr_proc_t, thr_proc);// set the thread number *before* creating the thread// so that it's visible in thr_proc when it starts to // run even before CreateThread returns thr_id->threadno = maxthreads;- const HANDLE hthread =- CreateThread (0, // lpThreadAttributes - 0, // dwStackSize - win32_thr_proc, // lpStartAddress - thr_arg, // lpParameter - 0, // dwCreationFlags - &nid); // lpThreadId + const uintptr_t hthread = + _beginthreadex (0, // lpThreadAttributes + 0, // dwStackSize + win32_thr_proc, // lpStartAddress + thr_arg, // lpParameter + 0, // dwCreationFlags + &nid); // lpThreadId- if (INVALID_HANDLE_VALUE == hthread) {+ if (!hthread) { thr_id->id = -1; thr_id->handle = 0; result = -1; } else { thr_id->id = nid; - thr_id->handle = hthread; + thr_id->handle = _RWSTD_REINTERPRET_CAST (void*, hthread); ++maxthreads; }