473,769 Members | 4,985 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

debugging multithreaded app

Hi,

i was debugging a multithreaded app, when i stumbled across some weird
behavior of the debugger.

in the destructor of my main object i send a stop event to the worker
thread, and then wait until that thread has finished.

m_Stop = true;
while(GetExitCo deThread() == STILL_RUNNING)
Sleep(50);

the strange thing is that if i break just before the m_Stop = true, and then
step through the while loop, the exit code is STILL_RUNNING forever. i can
step forever without the thread ever ending.
if a break just after the while loop, the thread has stopped without a
problem.

is this normal behavior?

kind regards,
Bruno.
Nov 17 '05 #1
4 1331
"Bruno van Dooren" <mi******@hotma il.com> wrote in message
news:eW******** ******@TK2MSFTN GP15.phx.gbl...
i was debugging a multithreaded app, when i stumbled across some weird
behavior of the debugger.

in the destructor of my main object i send a stop event to the worker
thread, and then wait until that thread has finished.

m_Stop = true;
while(GetExitCo deThread() == STILL_RUNNING)
Sleep(50);

the strange thing is that if i break just before the m_Stop = true, and
then step through the while loop, the exit code is STILL_RUNNING forever.
i can step forever without the thread ever ending.
if a break just after the while loop, the thread has stopped without a
problem.

is this normal behavior?


<guess mode on>
Could it be related to the fact that the debugger suspends _all_ threads on
encountering the breakpoint? Not having seen the source, I don't know how it
resumes them after the breakpoint is hit, but if it does it in a "lazy" way
in which the debugged thread is resumed first while the background threads
are resumed after the fact and if that resumption takes more than 50ms then
it may be that the other thread never runs.
</guess mode on>

What does the other thread do? Is it guaranteed to stop after you set
m_stop? If so, why use the hokey (IMO, YMMV) busy loop?

Regards,
Will
Nov 17 '05 #2
"Bruno van Dooren" <mi******@hotma il.com> wrote in message
news:eW******** ******@TK2MSFTN GP15.phx.gbl...
i was debugging a multithreaded app, when i stumbled across some weird
behavior of the debugger.

in the destructor of my main object i send a stop event to the worker
thread, and then wait until that thread has finished.

m_Stop = true;
while(GetExitCo deThread() == STILL_RUNNING)
Sleep(50);

[...]

I can't claim any insight into your problem, but this is the traditional way
to wait for a thread to exit:

m_Stop = true;
WaitForSingleOb ject(m_ThreadHa ndle, INFINITE);

There's no need to poll, as the original code does.

--
Tim Robinson
MVP, Windows SDK
Nov 17 '05 #3

"William DePalo [MVP VC++]" <wi***********@ mvps.org> wrote in message
news:%2******** *******@tk2msft ngp13.phx.gbl.. .
"Bruno van Dooren" <mi******@hotma il.com> wrote in message
news:eW******** ******@TK2MSFTN GP15.phx.gbl...
i was debugging a multithreaded app, when i stumbled across some weird
behavior of the debugger.

in the destructor of my main object i send a stop event to the worker
thread, and then wait until that thread has finished.

m_Stop = true;
while(GetExitCo deThread() == STILL_RUNNING)
Sleep(50);

the strange thing is that if i break just before the m_Stop = true, and
then step through the while loop, the exit code is STILL_RUNNING forever.
i can step forever without the thread ever ending.
if a break just after the while loop, the thread has stopped without a
problem.

is this normal behavior?


<guess mode on>
Could it be related to the fact that the debugger suspends _all_ threads
on encountering the breakpoint? Not having seen the source, I don't know
how it resumes them after the breakpoint is hit, but if it does it in a
"lazy" way in which the debugged thread is resumed first while the
background threads are resumed after the fact and if that resumption takes
more than 50ms then it may be that the other thread never runs.
</guess mode on>

What does the other thread do? Is it guaranteed to stop after you set
m_stop? If so, why use the hokey (IMO, YMMV) busy loop?

Regards,
Will


The reason for the while loop is that after the threads are stopped, a lot
of shared resources like notifiers and shared memory are cleaned up.
if i should not wait for the threads to finish, there is a race condition
between the functionality in the threads, and the cleanup code.

ps i just noticed that my code looked like
while(..)
;

without sleep. as a result there was probably not enough time for the
threads to resume.
still, i would have thought that it would only break the thread in which the
breakpoint was encountered.

thanks.
Bruno.
Nov 17 '05 #4

"Tim Robinson" <ti************ *************@n owhere.com> wrote in message
news:39******** *****@individua l.net...
"Bruno van Dooren" <mi******@hotma il.com> wrote in message
news:eW******** ******@TK2MSFTN GP15.phx.gbl...
i was debugging a multithreaded app, when i stumbled across some weird
behavior of the debugger.

in the destructor of my main object i send a stop event to the worker
thread, and then wait until that thread has finished.

m_Stop = true;
while(GetExitCo deThread() == STILL_RUNNING)
Sleep(50);

[...]

I can't claim any insight into your problem, but this is the traditional
way to wait for a thread to exit:

m_Stop = true;
WaitForSingleOb ject(m_ThreadHa ndle, INFINITE);

There's no need to poll, as the original code does.

--
Tim Robinson
MVP, Windows SDK


Thanks. i didn't know.
Bruno.
Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2983
by: Elbert Lev | last post by:
I started with Python two weeks ago and already saved some time and efforts while writing 2 programs: 1. database extraction and backup tool, which runs once a month and creates a snapshot of important data, compresses and saves it. 2. pop3 "watchdog", which reads e-mail from a pop3 mailbox and in the case there is no mail sends e-mail messages to technicians. (the presence of e-mail in the mailbox tells that the system I'm monitoring...
2
1945
by: Thomas Lindgaard | last post by:
Hello I have a multi-threaded web spider and it has a problem (probably several). Is there a way to make the debugger show me what my worker threads are doing? I can only get it to follow the main thread. I'm using Komodo Personal (trial). -- Regards /Thomas
2
6641
by: pradyumna | last post by:
In Project settins - C/C++ - Code Generation, what is the difference between the option "Multithreaded" and "Multithreaded DLL". I understand that on selecting multithreaded option, single and multithreaded applications can both use that dll, but what about multithreaded DLL option. Thanks
3
6028
by: Development | last post by:
I am creating 10 threads that do ecatly the same thing. I am having a very hard time debugging this scenario. It seems that by default when you are doing f10 or f11 all threads execute. You can see that by watching the thread window. When you freeze all threads but the one you are working on it then does not do anything. So does anybody have any experience debugging multithreaded apps in C# and could they share the best...
3
2601
by: groups | last post by:
Hi all, I've recently ported a rather large C application to run multithreaded. A few functions have seriously deteriorated in performance, in particular when accessing a rather large global array, that contains information that is shared among threads. Any idea, why the lines accessing this global array now take about 50x longer in the multithreaded application?
3
1666
by: | last post by:
Is it possible to have just a multithreaded sub procedure? What I need is a timer time_elapsed event (2 sec interval) send params to a sub that is multithreaded. I have a COM component used to send messages,faxes, etc.. The COM com component is licensed for 6 ports. I have an app that need to send messages/faxes very frequently (seconds) and to many, many people. What I want to do is have a sub that has 6 threads to send thse messages...
3
4599
by: Jake K | last post by:
I have a multithreaded application that I now want to convert into a Windows Service. Does application.run work in a windows service? Are there things to take into consideration when creating a multithreaded windows service as opposed to a multithreaded windows forms application? E.G. namespace whatever {
5
6397
by: John Henry | last post by:
I am back against the wall trying to migrate my multithreaded application from Python 2.3 to 2.5. The part of the code that's failing has to do with queues (2.3 queues and 2.5 queues are not the same). Since WingIDE doesn't support multithread debugging (they've been saying that one day they might support that - and that was 2003), I am starting to look for alternatives. debug under Eclipse/Pydev. I did a google search of this...
33
2889
by: fmassei | last post by:
Hello! I made a short piece of code that I find very useful for debugging, and I wanted to ask you if it is correct, somehow acceptable or if I simply reinvented the wheel. To deal with some bad bugs caused by memory leaks I ended up with this simple solution: I made one header file that, when included, replaces the malloc/calloc/realloc/free functions with some other functions that do the actual job and insert (or remove) the pointers to...
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10211
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9863
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8870
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5298
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3958
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3561
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.