You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stdcxx.apache.org by fa...@apache.org on 2007/07/26 19:23:24 UTC
svn commit: r559890 - /incubator/stdcxx/trunk/tests/src/thread.cpp
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 <Fa...@epam.com>
* thread.cpp (rw_thread_create) [_WIN32]: Use _beginthreadex() instead of CreateThread().
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;
}
RE: svn commit: r559890 - /incubator/stdcxx/trunk/tests/src/thread.cpp
Posted by Farid Zaripov <Fa...@epam.com>.
> -----Original Message-----
> From: Martin Sebor [mailto:msebor@gmail.com] On Behalf Of Martin Sebor
> Sent: Thursday, July 26, 2007 9:30 PM
> To: stdcxx-dev@incubator.apache.org
> Subject: Re: svn commit: r559890 -
> /incubator/stdcxx/trunk/tests/src/thread.cpp
>
> Wow, that sounds pretty important! I can't find this
> statement on the _beginthread() page though (below). Do you
> have a link?
>
> http://msdn2.microsoft.com/en-us/library/kdzttdcb(VS.80).aspx
You need to look CreateThread.
Here the link: http://msdn2.microsoft.com/en-us/library/ms682453.aspx
The last paragraph in the Remarks section:
-------------
A thread in an executable that calls the C run-time library (CRT) should
use
the _beginthreadex and _endthreadex functions for thread management
rather
than CreateThread and ExitThread; this requires the use of the
multi-threaded
version of the CRT. If a thread created using CreateThread calls the
CRT, the
CRT may terminate the process in low-memory conditions.
Farid.
Re: svn commit: r559890 - /incubator/stdcxx/trunk/tests/src/thread.cpp
Posted by Martin Sebor <se...@roguewave.com>.
Farid Zaripov wrote:
>> -----Original Message-----
>> From: Martin Sebor [mailto:msebor@gmail.com] On Behalf Of Martin Sebor
>> Sent: Thursday, July 26, 2007 9:15 PM
>> To: stdcxx-dev@incubator.apache.org
>> Subject: Re: svn commit: r559890 -
>> /incubator/stdcxx/trunk/tests/src/thread.cpp
>>
>> faridz@apache.org 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 <Fa...@epam.com>
>>>
>>> * 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().
>
>
> The _beginthreadex() allocates and initializes the thread local
> data before invoking the user thread function, and frees that data
> after return from user thread function.
>
>>>From MSDN:
> ----------
> A thread in an executable that calls the C run-time library (CRT)
> should use the _beginthread and _endthread functions for thread
> management rather than CreateThread and ExitThread; this requires
> the use of the multi-threaded version of the CRT.
> ----------
Wow, that sounds pretty important! I can't find this statement
on the _beginthread() page though (below). Do you have a link?
http://msdn2.microsoft.com/en-us/library/kdzttdcb(VS.80).aspx
Martin
RE: svn commit: r559890 - /incubator/stdcxx/trunk/tests/src/thread.cpp
Posted by Farid Zaripov <Fa...@epam.com>.
> -----Original Message-----
> From: Martin Sebor [mailto:msebor@gmail.com] On Behalf Of Martin Sebor
> Sent: Thursday, July 26, 2007 9:15 PM
> To: stdcxx-dev@incubator.apache.org
> Subject: Re: svn commit: r559890 -
> /incubator/stdcxx/trunk/tests/src/thread.cpp
>
> faridz@apache.org 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 <Fa...@epam.com>
> >
> > * 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().
The _beginthreadex() allocates and initializes the thread local
data before invoking the user thread function, and frees that data
after return from user thread function.
>From MSDN:
----------
A thread in an executable that calls the C run-time library (CRT)
should use the _beginthread and _endthread functions for thread
management rather than CreateThread and ExitThread; this requires
the use of the multi-threaded version of the CRT.
----------
Farid.
Re: svn commit: r559890 - /incubator/stdcxx/trunk/tests/src/thread.cpp
Posted by Martin Sebor <se...@roguewave.com>.
faridz@apache.org 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 <Fa...@epam.com>
>
> * 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;
> }
>
>
>
>