<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>Message</TITLE>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.2800.1141" name=GENERATOR></HEAD>
<BODY>
<DIV><SPAN class=221014805-12032003><FONT face=Arial color=#0000ff size=2>Hi
All</FONT></SPAN></DIV>
<DIV><SPAN class=221014805-12032003><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=221014805-12032003><FONT face=Arial color=#0000ff size=2>I have
been able to solve the problem. But the root cause is still not clear. Following
is the scenario in the code.</FONT></SPAN></DIV>
<DIV><SPAN class=221014805-12032003><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=221014805-12032003><FONT face=Arial color=#0000ff size=2>I have
a class CriticalSection which is being used in the class for
locking.</FONT></SPAN></DIV>
<DIV><SPAN class=221014805-12032003><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=221014805-12032003><FONT face=Arial color=#0000ff
size=2>Following is the class</FONT></SPAN></DIV>
<DIV><SPAN class=221014805-12032003><FONT face=Arial color=#0000ff
size=2>typedef struct _critsection {<BR>
pthread_t Owner;<BR>
int LockDepth;<BR>
pthread_mutex_t Lock;<BR>} CRITICAL_SECTION;</FONT></SPAN></DIV>
<DIV><SPAN class=221014805-12032003><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=221014805-12032003><FONT face=Arial color=#0000ff
size=2>typedef class CriticalSection {<BR>public:<BR>
CriticalSection() { CriticalSectionLock.Owner =
0; CriticalSectionLock.Lock =
GenericMutexInitializer; }<BR>
int Lock() { return EnterCriticalSection(&CriticalSectionLock); } //for
locking the mutex<BR> void Unlock() {
LeaveCriticalSection(&CriticalSectionLock); } //for unlocking the
mutex<BR>private:<BR> CRITICAL_SECTION
CriticalSectionLock;<BR>}CCriticalSection;</FONT></SPAN></DIV>
<DIV><SPAN class=221014805-12032003><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=221014805-12032003><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=221014805-12032003><FONT face=Arial color=#0000ff size=2>My
code uses the above class as</FONT></SPAN></DIV>
<DIV><SPAN class=221014805-12032003><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=221014805-12032003><FONT face=Arial color=#0000ff size=2>class
myClass {</FONT></SPAN></DIV>
<DIV><SPAN class=221014805-12032003><FONT face=Arial color=#0000ff
size=2>private</FONT></SPAN></DIV>
<DIV><SPAN class=221014805-12032003><FONT face=Arial color=#0000ff
size=2>.</FONT></SPAN></DIV>
<DIV><SPAN class=221014805-12032003><FONT face=Arial color=#0000ff
size=2>.</FONT></SPAN></DIV>
<DIV><SPAN class=221014805-12032003><FONT face=Arial color=#0000ff
size=2>.</FONT></SPAN></DIV>
<DIV><SPAN class=221014805-12032003><FONT face=Arial color=#0000ff
size=2>CCriticalSection myLock;</FONT></SPAN></DIV>
<DIV><SPAN class=221014805-12032003><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=221014805-12032003><FONT face=Arial color=#0000ff
size=2>public:</FONT></SPAN></DIV>
<DIV><SPAN class=221014805-12032003><FONT face=Arial color=#0000ff size=2>void
Lock(){myLock.Lock();}</FONT></SPAN></DIV>
<DIV><SPAN class=221014805-12032003><FONT face=Arial color=#0000ff
size=2>};</FONT></SPAN></DIV>
<DIV><SPAN class=221014805-12032003><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=221014805-12032003><FONT face=Arial color=#0000ff
size=2>main()</FONT></SPAN></DIV>
<DIV><SPAN class=221014805-12032003><FONT face=Arial color=#0000ff
size=2>{</FONT></SPAN></DIV>
<DIV><SPAN class=221014805-12032003><FONT face=Arial color=#0000ff
size=2>.</FONT></SPAN></DIV>
<DIV><SPAN class=221014805-12032003><FONT face=Arial color=#0000ff
size=2>.</FONT></SPAN></DIV>
<DIV><SPAN class=221014805-12032003><FONT face=Arial color=#0000ff
size=2>myClass *myObj = new myObj();</FONT></SPAN></DIV>
<DIV><SPAN class=221014805-12032003><FONT face=Arial color=#0000ff
size=2>myObj.Lock()</FONT></SPAN></DIV>
<DIV><SPAN class=221014805-12032003><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=221014805-12032003><FONT face=Arial color=#0000ff
size=2>.</FONT></SPAN></DIV>
<DIV><SPAN class=221014805-12032003><FONT face=Arial color=#0000ff
size=2>.</FONT></SPAN></DIV>
<DIV><SPAN class=221014805-12032003><FONT face=Arial color=#0000ff
size=2>.</FONT></SPAN></DIV>
<DIV><SPAN class=221014805-12032003><FONT face=Arial color=#0000ff
size=2>}</FONT></SPAN></DIV>
<DIV><SPAN class=221014805-12032003><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=221014805-12032003><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=221014805-12032003><FONT face=Arial color=#0000ff size=2>Now in
debug mode, initializer of "CriticalSection" is not being called. & then
locking fails. As soon as I change the name of class "CriticalSection" to
some other name.. say "ACriticalSection". code works fine.</FONT></SPAN></DIV>
<DIV><SPAN class=221014805-12032003><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=221014805-12032003><FONT face=Arial color=#0000ff size=2>what
can this mean?? & why this behaviour only in the debug
mode?????</FONT></SPAN></DIV>
<DIV><SPAN class=221014805-12032003></SPAN> </DIV>
<DIV><SPAN class=221014805-12032003><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV></DIV>
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left><FONT face=Tahoma
size=2>-----Original Message-----<BR><B>From:</B> Vincent Penquerc'h
[mailto:Vincent.Penquerch@artworks.co.uk] <BR><B>Sent:</B> Friday, March 07,
2003 11:03 PM<BR><B>To:</B>
'linuxcprogramming@lists.linux.org.au'<BR><B>Subject:</B> RE: [LCP]FW:
pthread_mutex_lock call hangs<BR><BR></FONT></DIV>
<P><FONT size=2>> > Only difference between two build is of "-g" flag.
There is </FONT></P>
<P><FONT size=2>And about the link ? Are different libs being linked against
?</FONT> <BR><FONT size=2>Sorry to state the obvious.</FONT> <BR><FONT
size=2>Only think I can think of is timing issues. Debug info in the exe</FONT>
<BR><FONT size=2>could *maybe* cause more disk load at startup, which could
influence</FONT> <BR><FONT size=2>the thread timing. Just a shot in the dark,
really.</FONT> <BR><FONT size=2>To make sure it's not something else that -g,
strip your program</FONT> <BR><FONT size=2>compiled with -g, and test it.
Stripped program should be the same</FONT> <BR><FONT size=2>as the release
one.</FONT> </P>
<P><FONT size=2>(Sorry about the HTML, it's converted after my mailer sends
plain</FONT> <BR><FONT size=2>text).</FONT> </P>
<P><FONT size=2>-- </FONT><BR><FONT size=2>Vincent Penquerc'h
</FONT></P></BODY></HTML>