[gdal-dev] Re: Thread Synchronization in 1.5.0?

Frank Warmerdam warmerdam at pobox.com
Fri Feb 8 16:28:11 EST 2008


Martin Chapman wrote:
> Frank,
> 
> Just as an FYI, I noticed that the Win32 function CreateThread() is used on
> line 610 of file C:\software\GDAL\port\cpl_multiproc.cpp.  This function may
> not be the best for creating a thread on windows.  _beginthreadex() is the
> preferred way to invoke threads in C on windows because it copies all global
> variables in the Win32 API into the thread local storage for each thread
> making the Win32 API usage thread safe, where the older C style
> CreateThread() function does not. This may or may not be an issue for gdal
> depending on what other Win32 API calls are made from within gdal on
> windows.  
> 
> Please advise me if anyone thinks this is incorrect.

Martin,

Currently the only place we use CreateThread ourselves is in gdalwarp
when trying to use a second thread to do io while the main thread
does resampling.  So I doubt there is much practical significance
for now.

But, yes, I can see that this might be valuable if the function is
used by anyone else higher up the stack.

Is this a distinct approach to use /MT which I gathered provided for a
thread-safe C runtime?  GDAL doesn't really use very many direct win32
calls, and I'm not aware of it using any win32 globals that aren't
part of the C runtime (like errno).

Can you think of any downside to using _beginthreadex()?  Perhaps
you could file a ticket with this suggestion or even just go ahead
and change it yourself in trunk.

Best regards,
-- 
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | President OSGeo, http://osgeo.org



More information about the gdal-dev mailing list