cURL / Mailing Lists / curl-library / Single Mail

curl-library

Multi-threading deadlock in Windows XP 64-bit

From: George Woltman <woltman_at_alum.mit.edu>
Date: Wed, 24 Oct 2007 13:03:19 -0400

I'm using 64-bit Windows XP and MS Visual Studio 2005. I've run into
the following deadlock
condition and don't really know what to do about it.

My program does all communication in a separate thread. It calls
curl_easy_perform, which calls
the curl resolver. This creates a thread. The C runtime library
implementation of _beginthreadex
calls GetModuleHandle ("KERNEL32.DLL"). If my main message
processing thread happens to
call LoadIcon or SetIcon at this time, then BAM - I've deadlocked.

I don't fully understand what is causing the deadlock. Google
reveals some articles about the
dangers of doing any real work in DllMain because the OS has acquired
a lock. Maybe
KERNEL32.DLL's DllMain is initializing some thread-local storage and
tries to acquire Kernel
locks that LoadIcon or SetIcon is also trying to get.

I know this is more of an OS bug or a C runtime library bug. Questions:
1) Can anyone explain in better detail the cause of the deadlock
and/or suggest a workaround?
2) Is there a way to have the resolver not spawn a thread or cache
and reuse threads?
Received on 2007-10-24