Click here to Skip to main content
15,887,135 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Special character as button label Pin
David Crow26-Feb-10 9:13
David Crow26-Feb-10 9:13 
AnswerRe: Special character as button label Pin
Avi Berger26-Feb-10 12:13
Avi Berger26-Feb-10 12:13 
QuestionConditiona Modification of VERSIONINFO values Pin
softwaremonkey26-Feb-10 6:13
softwaremonkey26-Feb-10 6:13 
AnswerRe: Conditiona Modification of VERSIONINFO values Pin
Richard MacCutchan26-Feb-10 6:34
mveRichard MacCutchan26-Feb-10 6:34 
GeneralRe: Conditiona Modification of VERSIONINFO values Pin
softwaremonkey26-Feb-10 6:45
softwaremonkey26-Feb-10 6:45 
GeneralRe: Conditiona Modification of VERSIONINFO values Pin
Richard MacCutchan26-Feb-10 7:33
mveRichard MacCutchan26-Feb-10 7:33 
AnswerRe: Conditiona Modification of VERSIONINFO values Pin
cmk26-Feb-10 14:04
cmk26-Feb-10 14:04 
QuestionDeadlock occurs in Function Scoped Static variables (Thread Unsafe in VC++) Pin
Mohammed_Irfan26-Feb-10 2:52
Mohammed_Irfan26-Feb-10 2:52 
The question is how function-level statics are constructed when the function is called on multiple threads?

Problem Description: Deadlock occurs and my application doesn't get terminated. During initialization of local static variable it tries to acquire MSVCR80!_lock and never gets hold on the lock.

Below is the calls stack and you will see that it will never get hold on the lock _mlock

(_EXIT_LOCK1); //C:\Program Files\Microsoft Visual Studio 8\VC\crt\src\crt0dat.c

ntdll!RtlpWaitForCriticalSection+0x132
ntdll!RtlEnterCriticalSection+0x46
MSVCR80!_lock+0x2e MyDLL!_onexit+0x36 [f:\sp\vctools\crt_bld\self_x86\crt\src\atonexit.c @ 103] MyDLL!atexit+0x9 [f:\sp\vctools\crt_bld\self_x86\crt\src\atonexit.c @ 127] MyDLL!__DllMainCRTStartup+0x7a [f:\sp\vctools\crt_bld\self_x86\crt\src\crtdll.c @ 498] MyDLL!_DllMainCRTStartup+0x1d [f:\sp\vctools\crt_bld\self_x86\crt\src\crtdll.c @ 462] ntdll!LdrpCallInitRoutine+0x14

// Code snippet below
void main()
{

atexit(MyCallBack);
exit(0);

}

void MyCallBack()
{

// Waitingforsingleobject() // Waits until all threads are terminated

}

The EXE call DllMain with DLL_THREAD_DETACH flag and we have an explicit handling as shown below

BOOL APIENTRY DllMain( HANDLE, DWORD dwReason, LPVOID )
{
if(dwReason == DLL_THREAD_DETACH)
{
F1();
F2();
}
}

F1()
{

const static CComBSTR bstrMethod = __ FUNCTION __ ;

}

F2()
{

const static CComBSTR bstrMethod = __ FUNCTION __ ;

}

Is it thread safe to have local static initialization within a function. Also I noticed if static variable is once initialized before the exit() of main application I don't see any problem. Can any one please explain what might be issue?

Note: But when I make static variable as non static the deadlock doesn't occur and problem is solved.

Also let me know any alternate solution which might help in this situation Eagerly waiting for reply.
irfan

AnswerRe: Deadlock occurs in Function Scoped Static variables (Thread Unsafe in VC++) Pin
Avi Berger26-Feb-10 5:20
Avi Berger26-Feb-10 5:20 
GeneralRe: Deadlock occurs in Function Scoped Static variables (Thread Unsafe in VC++) Pin
Mohammed_Irfan28-Feb-10 22:06
Mohammed_Irfan28-Feb-10 22:06 
QuestionKilling a process by name Pin
transoft26-Feb-10 2:21
transoft26-Feb-10 2:21 
AnswerRe: Killing a process by name Pin
Eugen Podsypalnikov26-Feb-10 2:35
Eugen Podsypalnikov26-Feb-10 2:35 
AnswerRe: Killing a process by name Pin
Maximilien26-Feb-10 2:40
Maximilien26-Feb-10 2:40 
AnswerRe: Killing a process by name Pin
wangningyu26-Feb-10 20:22
wangningyu26-Feb-10 20:22 
AnswerRe: Killing a process by name Pin
Bram van Kampen26-Feb-10 21:41
Bram van Kampen26-Feb-10 21:41 
QuestionBUG IN C (LINKED LIST CODE).......please Help me Pin
sarojbobby26-Feb-10 1:59
sarojbobby26-Feb-10 1:59 
AnswerRe: BUG IN C (LINKED LIST CODE).......please Help me Pin
Cedric Moonen26-Feb-10 2:05
Cedric Moonen26-Feb-10 2:05 
JokeRe: BUG IN C (LINKED LIST CODE).......please Help me Pin
Nelek26-Feb-10 3:03
protectorNelek26-Feb-10 3:03 
JokeRe: BUG IN C (LINKED LIST CODE).......please Help me Pin
Cedric Moonen26-Feb-10 3:13
Cedric Moonen26-Feb-10 3:13 
JokeRe: BUG IN C (LINKED LIST CODE).......please Help me Pin
Nelek26-Feb-10 3:20
protectorNelek26-Feb-10 3:20 
GeneralRe: BUG IN C (LINKED LIST CODE).......please Help me Pin
Cedric Moonen26-Feb-10 3:46
Cedric Moonen26-Feb-10 3:46 
JokeRe: BUG IN C (LINKED LIST CODE).......please Help me Pin
Nelek26-Feb-10 3:56
protectorNelek26-Feb-10 3:56 
GeneralRe: BUG IN C (LINKED LIST CODE).......please Help me Pin
CPallini26-Feb-10 6:02
mveCPallini26-Feb-10 6:02 
AnswerRe: BUG IN C (LINKED LIST CODE).......please Help me Pin
CPallini26-Feb-10 2:08
mveCPallini26-Feb-10 2:08 
AnswerRe: BUG IN C (LINKED LIST CODE).......please Help me Pin
Avi Berger26-Feb-10 7:02
Avi Berger26-Feb-10 7:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.