thamagates / mongoose

Automatically exported from code.google.com/p/mongoose
MIT License
0 stars 0 forks source link

Win32 threads can cause runtime-library resource leaks #186

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The start_thread routine for Win32 builds uses the Kernel32 CreateThread 
procedure, however this method is reserved for use within runtime libraries.

Both MinGW and MSVC provide _beginthreadex (in process.h), which is implemented 
in their runtime libraries, and gives the runtime library an opportunity to 
release thread-local resources.

Specifically the MSDN documentation states:
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.

Additionally the MinGW documentation states:
As MinGW uses the standard Microsoft C runtime library which comes with 
Windows, you should be careful and use the correct function to generate a new 
thread. In particular, the ~CreateThread function will not setup the stack 
correctly for the C runtime library. You should use _beginthreadex instead, 
which is (almost) completely compatible with ~CreateThread.

Original issue reported on code.google.com by Malcolm....@gmail.com on 13 Oct 2010 at 12:13

GoogleCodeExporter commented 9 years ago

Original comment by valenok on 21 Jun 2011 at 9:41

GoogleCodeExporter commented 9 years ago
Submitted 
https://code.google.com/p/mongoose/source/detail?r=0c7117beeeb0ef95eaa7166b99dbc
3e14d1b1972
Thank you.

Original comment by valenok on 26 Aug 2011 at 12:04