Board index » Visual Studio » deadlock question

deadlock question

Visual Studio215
Hi,

I'm getting that error from Boundchecker when I use CMutex instead

CCriticalSection:

"A Window was created by thread 0x1C20, Use the MsgWaitFor* API calls

instead of WaitForSingleObject to avoid deadlocks or user interface

'lockups' that may occur.?



code looks like:

CMutex m_mutex;

CSingleLock mlock(&m_mutex);

mlock.Lock(5000);

mlock.Unlock();



Should I warry about that?

thanks


-
 

Re:deadlock question

alladyn wrote:

Quote
Hi,

I'm getting that error from Boundchecker when I use CMutex instead

CCriticalSection:

"A Window was created by thread 0x1C20, Use the MsgWaitFor* API calls

instead of WaitForSingleObject to avoid deadlocks or user interface

'lockups' that may occur.?



code looks like:

CMutex m_mutex;

CSingleLock mlock(&m_mutex);

mlock.Lock(5000);

mlock.Unlock();



Should I warry about that?

thanks







Yes, you should worry about that. If you have a window in the same

thread as this code, and Windows sends a message to the window, your

program is in danger of looking broken and being labeled "Program is not

responding."



It's rather unclear from the above code what you are trying to accomplish.



--

Scott McPhillips [VC++ MVP]



-

Re:deadlock question

If it is in your main GUI thread, any long computation is going to lock up the GUI thread

and thus delay updates.



The selection of 5000 as a timeout is suggestive of serious problems. Furthermore, you

seem to assume that if you pass the lock you have it; the correct code would test the

result of the Lock method to be sure that you actually HAD the lock before proceeding.

Note: if your program does not work correctly with INFINITE, your program has a bug so

serious that it requires redesign. Note: If you do not check the value of Lock() with a

timeout value *other* than INFINITE, you have a fatal error in your code right at that

spot.



Otherwise, this is BoundsChecker being perhaps overly conservative.

joe



On Tue, 9 Aug 2005 17:16:24 -0400, "alladyn" <alladyn@yahoo.com>wrote:



Quote
Hi,

I'm getting that error from Boundchecker when I use CMutex instead

CCriticalSection:

"A Window was created by thread 0x1C20, Use the MsgWaitFor* API calls

instead of WaitForSingleObject to avoid deadlocks or user interface

'lockups' that may occur.?



code looks like:

CMutex m_mutex;

CSingleLock mlock(&m_mutex);

mlock.Lock(5000);

mlock.Unlock();



Should I warry about that?

thanks





Joseph M. Newcomer [MVP]

email: newcomer@flounder.com

Web: www.flounder.com">www.flounder.com

MVP Tips: www.flounder.com/mvp_tips.htm">www.flounder.com/mvp_tips.htm

-

Re:deadlock question

Hi,

this is internet Explorer toolbar application, I'm trying to guard parts of

code where I'm writing to same file.

Internet explorer looks like most of the time working by

creating new thread when open new window, but sometimes it does create new

process. Thats why I use Mutex. Originally I had INFINITE and it's working,

but because of Boundchecker I thought that if I put timeout it will be

better, but you're right guys I should check the lock after timeout.



thanks a lot



"Scott McPhillips [MVP]" <org-dot-mvps-at-scottmcp>wrote in message

Quote
alladyn wrote:

>Hi,

>I'm getting that error from Boundchecker when I use CMutex instead

>CCriticalSection:

>"A Window was created by thread 0x1C20, Use the MsgWaitFor* API calls

>instead of WaitForSingleObject to avoid deadlocks or user interface

>'lockups' that may occur.?

>

>code looks like:

>CMutex m_mutex;

>CSingleLock mlock(&m_mutex);

>mlock.Lock(5000);

>mlock.Unlock();

>

>Should I warry about that?

>thanks

>

>



Yes, you should worry about that. If you have a window in the same thread

as this code, and Windows sends a message to the window, your program is

in danger of looking broken and being labeled "Program is not responding."



It's rather unclear from the above code what you are trying to accomplish.



--

Scott McPhillips [VC++ MVP]







-

Re:deadlock question

Yes, but if I give timeout, why it's a problem,

after 5sec it willbe relased right?



"Scott McPhillips [MVP]" <org-dot-mvps-at-scottmcp>wrote in message

Quote
alladyn wrote:

>Hi,

>I'm getting that error from Boundchecker when I use CMutex instead

>CCriticalSection:

>"A Window was created by thread 0x1C20, Use the MsgWaitFor* API calls

>instead of WaitForSingleObject to avoid deadlocks or user interface

>'lockups' that may occur.?

>

>code looks like:

>CMutex m_mutex;

>CSingleLock mlock(&m_mutex);

>mlock.Lock(5000);

>mlock.Unlock();

>

>Should I warry about that?

>thanks

>

>



Yes, you should worry about that. If you have a window in the same thread

as this code, and Windows sends a message to the window, your program is

in danger of looking broken and being labeled "Program is not responding."



It's rather unclear from the above code what you are trying to accomplish.



--

Scott McPhillips [VC++ MVP]







-