Threads #3

Hello NG,

till now I have used timers, but I want to change my programme to use
threads.
I know that one timer routine sometimes crashes and ends my programme.
I don't know threads very well, so I have these questions:
1. If a thread crashes, does the whole programme crash too, or do the other
threads still work?
2. If they still continue working: Is there a possibility to recognize that
the thread has crashed so that I can restart it?

Thanks for help,
Guido Franzke


0
guidof73 (128)
1/13/2006 2:10:33 PM
vc.mfc 33608 articles. 0 followers. Follow

11 Replies
497 Views

Similar Articles

[PageSpeed] 19

yes, if you have access violations,null pointer access and other unhandled 
exceptions in the thread,
your program would terminate.

Well, If your program happen to survive a thread crash, you can use the 
WaitForSingleObject(hThread , INFINITE)
to determine if the thread has run out of execution.
-- 
Vipin Aravind
Microsoft - MVP

"Guido Franzke" <guidof73@yahoo.de> wrote in message 
news:%23KVgMuEGGHA.916@TK2MSFTNGP10.phx.gbl...
> Hello NG,
>
> till now I have used timers, but I want to change my programme to use
> threads.
> I know that one timer routine sometimes crashes and ends my programme.
> I don't know threads very well, so I have these questions:
> 1. If a thread crashes, does the whole programme crash too, or do the 
> other
> threads still work?
> 2. If they still continue working: Is there a possibility to recognize 
> that
> the thread has crashed so that I can restart it?
>
> Thanks for help,
> Guido Franzke
>
> 


0
vipin (697)
1/13/2006 3:09:53 PM
Vipin wrote:
> yes, if you have access violations,null pointer access and other unhandled
> exceptions in the thread,
> your program would terminate.
>
> Well, If your program happen to survive a thread crash, you can use the
> WaitForSingleObject(hThread , INFINITE)
> to determine if the thread has run out of execution.

Problem there is that if the thread has not terminated, the thread you
are calling WaitFor from will freeze until it does terminate.

0
darsant (187)
1/13/2006 5:29:51 PM
You need to run a watcher thread for that :)

-- 
Vipin Aravind
Microsoft - MVP

"Josh McFarlane" <darsant@gmail.com> wrote in message 
news:1137173391.384514.156940@g43g2000cwa.googlegroups.com...
> Vipin wrote:
>> yes, if you have access violations,null pointer access and other 
>> unhandled
>> exceptions in the thread,
>> your program would terminate.
>>
>> Well, If your program happen to survive a thread crash, you can use the
>> WaitForSingleObject(hThread , INFINITE)
>> to determine if the thread has run out of execution.
>
> Problem there is that if the thread has not terminated, the thread you
> are calling WaitFor from will freeze until it does terminate.
> 


0
vipin (697)
1/13/2006 5:42:39 PM
Vipin wrote:
> You need to run a watcher thread for that :)

See, I figure that would be a pain to do.

I'd just make sure my thread was tight and safe, and then have a flag
or something that indicated it's status, or post a message to the main
thread when it terminated.

0
darsant (187)
1/13/2006 5:55:58 PM
If I was answering this thread, I would tell the OP to fix the bug that
crashes the program instead of finding ways to hide it.

AliR.

"Josh McFarlane" <darsant@gmail.com> wrote in message
news:1137174958.483195.307310@g47g2000cwa.googlegroups.com...
> Vipin wrote:
> > You need to run a watcher thread for that :)
>
> See, I figure that would be a pain to do.
>
> I'd just make sure my thread was tight and safe, and then have a flag
> or something that indicated it's status, or post a message to the main
> thread when it terminated.
>


0
AliR3470 (3235)
1/13/2006 7:10:14 PM
Think again. You had do my way if you had want to track the threads as 
independent  module.
You can write more object oriented code using my method over yours.

Your method says use a global variable or define a helper windows 
message(and also assumes the fact
that the code responsible for state tracking would be run always by that 
thread),and Also replication
of same state tracking code in each threading code, things which are ok if 
your project  is few lines,
but really worth avoiding as the project grows.

-- 
Vipin Aravind
Microsoft - MVP

"Josh McFarlane" <darsant@gmail.com> wrote in message 
news:1137174958.483195.307310@g47g2000cwa.googlegroups.com...
> Vipin wrote:
>> You need to run a watcher thread for that :)
>
> See, I figure that would be a pain to do.
>
> I'd just make sure my thread was tight and safe, and then have a flag
> or something that indicated it's status, or post a message to the main
> thread when it terminated.
> 


0
vipin (697)
1/13/2006 7:17:54 PM
Who is answering the crash scenario? That has to fixed anyway.

We are talking on the thread tracking code.

-- 
Vipin Aravind
Microsoft - MVP

"AliR" <AliR@online.nospam> wrote in message 
news:qWSxf.1149$PL5.1071@newssvr11.news.prodigy.com...
> If I was answering this thread, I would tell the OP to fix the bug that
> crashes the program instead of finding ways to hide it.
>
> AliR.
>
> "Josh McFarlane" <darsant@gmail.com> wrote in message
> news:1137174958.483195.307310@g47g2000cwa.googlegroups.com...
>> Vipin wrote:
>> > You need to run a watcher thread for that :)
>>
>> See, I figure that would be a pain to do.
>>
>> I'd just make sure my thread was tight and safe, and then have a flag
>> or something that indicated it's status, or post a message to the main
>> thread when it terminated.
>>
>
> 


0
vipin (697)
1/13/2006 7:18:33 PM
Vipin wrote:
> Think again. You had do my way if you had want to track the threads as
> independent  module.
> You can write more object oriented code using my method over yours.
> Your method says use a global variable or define a helper windows
> message(and also assumes the fact
> that the code responsible for state tracking would be run always by that
> thread),and Also replication
> of same state tracking code in each threading code, things which are ok if
> your project  is few lines,
> but really worth avoiding as the project grows.

So, you're telling me you can track the exact state of a thread from
outside of the thread without some sort of interface to inquire about
the thread status?

My method does not use a global variable. I require threads that I
launch to report back to the parent thread via PostMessage if there's
an error condition or on success. This allows me to define the thread
implementation in the thread, and then register messages declared on
the thread's code to be transmitted back to the main application.

Then, the main application can have it's own code to handle any errors
that the working thread may have.

If you abstract this to another thread that simply waits on the
original thread, how do you inquire the status of the new "watcher"
thread. Wait on it? You're at a freeze position again if your worker
thread has locked up.

What happens if an error occurs in the worker thread? It's dead. You
have no way to pass why it died back to your original caller, so the
caller has to assume it failed completely and restart from scratch.

State management of the worker thread requires at least one way
communication, otherwise you have two possible states: Running or not
running.

0
darsant (187)
1/13/2006 8:00:35 PM
I was just pointing out that you guys are going off on a tangent.  The
original poster said he had a routine that crashes, wants to put it in a
thread so that when it crashes it wouldn't crash the entire program!

AliR.


"Vipin" <Vipin@nospam.com> wrote in message
news:eNZInYHGGHA.644@TK2MSFTNGP09.phx.gbl...
> Who is answering the crash scenario? That has to fixed anyway.
>
> We are talking on the thread tracking code.
>
> -- 
> Vipin Aravind
> Microsoft - MVP
>
> "AliR" <AliR@online.nospam> wrote in message
> news:qWSxf.1149$PL5.1071@newssvr11.news.prodigy.com...
> > If I was answering this thread, I would tell the OP to fix the bug that
> > crashes the program instead of finding ways to hide it.
> >
> > AliR.
> >
> > "Josh McFarlane" <darsant@gmail.com> wrote in message
> > news:1137174958.483195.307310@g47g2000cwa.googlegroups.com...
> >> Vipin wrote:
> >> > You need to run a watcher thread for that :)
> >>
> >> See, I figure that would be a pain to do.
> >>
> >> I'd just make sure my thread was tight and safe, and then have a flag
> >> or something that indicated it's status, or post a message to the main
> >> thread when it terminated.
> >>
> >
> >
>
>


0
AliR3470 (3235)
1/13/2006 8:29:32 PM
Its fun sometimes.

-- 
Vipin Aravind
Microsoft - MVP

"AliR" <AliR@online.nospam> wrote in message 
news:M4Uxf.555$Jd.451@newssvr25.news.prodigy.net...
>I was just pointing out that you guys are going off on a tangent.  The
> original poster said he had a routine that crashes, wants to put it in a
> thread so that when it crashes it wouldn't crash the entire program!
>
> AliR.
>
>
> "Vipin" <Vipin@nospam.com> wrote in message
> news:eNZInYHGGHA.644@TK2MSFTNGP09.phx.gbl...
>> Who is answering the crash scenario? That has to fixed anyway.
>>
>> We are talking on the thread tracking code.
>>
>> -- 
>> Vipin Aravind
>> Microsoft - MVP
>>
>> "AliR" <AliR@online.nospam> wrote in message
>> news:qWSxf.1149$PL5.1071@newssvr11.news.prodigy.com...
>> > If I was answering this thread, I would tell the OP to fix the bug that
>> > crashes the program instead of finding ways to hide it.
>> >
>> > AliR.
>> >
>> > "Josh McFarlane" <darsant@gmail.com> wrote in message
>> > news:1137174958.483195.307310@g47g2000cwa.googlegroups.com...
>> >> Vipin wrote:
>> >> > You need to run a watcher thread for that :)
>> >>
>> >> See, I figure that would be a pain to do.
>> >>
>> >> I'd just make sure my thread was tight and safe, and then have a flag
>> >> or something that indicated it's status, or post a message to the main
>> >> thread when it terminated.
>> >>
>> >
>> >
>>
>>
>
> 


0
vipin (697)
1/13/2006 8:43:15 PM
With PostMessage(...) you have made a bigger assumption that people would be 
doing
only GUI programming and there would be a message pump in the application 
and so on.

Since the OP is asleep, let us also go underground.
-- 
Vipin Aravind
Microsoft - MVP

"Josh McFarlane" <darsant@gmail.com> wrote in message 
news:1137182435.541911.227430@g44g2000cwa.googlegroups.com...
> Vipin wrote:
>> Think again. You had do my way if you had want to track the threads as
>> independent  module.
>> You can write more object oriented code using my method over yours.
>> Your method says use a global variable or define a helper windows
>> message(and also assumes the fact
>> that the code responsible for state tracking would be run always by that
>> thread),and Also replication
>> of same state tracking code in each threading code, things which are ok 
>> if
>> your project  is few lines,
>> but really worth avoiding as the project grows.
>
> So, you're telling me you can track the exact state of a thread from
> outside of the thread without some sort of interface to inquire about
> the thread status?
>
> My method does not use a global variable. I require threads that I
> launch to report back to the parent thread via PostMessage if there's
> an error condition or on success. This allows me to define the thread
> implementation in the thread, and then register messages declared on
> the thread's code to be transmitted back to the main application.
>
> Then, the main application can have it's own code to handle any errors
> that the working thread may have.
>
> If you abstract this to another thread that simply waits on the
> original thread, how do you inquire the status of the new "watcher"
> thread. Wait on it? You're at a freeze position again if your worker
> thread has locked up.
>
> What happens if an error occurs in the worker thread? It's dead. You
> have no way to pass why it died back to your original caller, so the
> caller has to assume it failed completely and restart from scratch.
>
> State management of the worker thread requires at least one way
> communication, otherwise you have two possible states: Running or not
> running.
> 


0
vipin (697)
1/13/2006 8:48:08 PM
Reply:

Similar Artilces:

Problem with blocking of main thread with other thread
I have a problem with blocking of main thread: My application contains an interpreter and I need to write a debugger for it. The mainframe creates a thread that is interpreting instructions. When I need to break execution of instruction thread, I use WaitForSingleObject(m_WaitEventHandle, INFINITE); in the interpreter thread. Everything works fine until the window is opened from the interpreter. Then the mainframe freezes. When I break execution in VC the call stack for interpreter thread shows: � NTDLL! � KERNEL32! � CDebugManager::CheckBreakpoints() � CInterpreterThread::Run() � _Afx...

Where is my thread?
I posted a question about "Search for a value in multi-dimensionla array" an hour ago; where did that go? On 5/17/2010 17:38, Rick wrote: > I posted a question about "Search for a value in multi-dimensionla array" an > hour ago; where did that go? If you mean the one beginning with "Seach", posted almost half an hour before this one, it is there. :) On 5/17/2010 11:51 AM, Jackie wrote: > On 5/17/2010 17:38, Rick wrote: >> I posted a question about "Search for a value in multi-dimensionla >> array" an >> hour ag...

Direct upgrade from CRM 1.0 to CRM 3.0
Has anybody sucessfully done an upgrade from 1.0 to 3.0 with out first doing an upgrade to 1.2? If so please can you give me some tips how to do this. Thanks ...

Simple Thread
I have created a thread in my MFC Dialog based application, in the thread function i want to have access to a user interface control that is attached to the main dialog. How can I do it? Regards, Mystique Mystique wrote: > I have created a thread in my MFC Dialog based application, in the thread > function i want to have access to a user interface control that is attached > to the main dialog. > How can I do it? > > Regards, > Mystique > > Indirectly, by posting a message to the main thread asking it to update the control. http://www.mvps.org/vcfaq/mfc/12.ht...

Lookup and add values from 3 columns
I have a worksheet with stock locations in, Column A = Aisle, Column B Location Column C= Level Column D=Item number I would like to return the value in column A through C on a new shee when I put in a certain item number, that matches value in column D kind of like a pivot table but not! Any ideas -- Message posted from http://www.ExcelForum.com Hi One way is to use something like this: =OFFSET(D1,MATCH(Sheet2!A1,D:D,0)-1,-1) This will return whatever is in column C - where the number in Sheet2!A1 matches column D. To return the same from B and A use: =OFFSET(D1,MATCH(A1,D:D,0)-1,-2) a...

Diaglog/Threading Data Exchange Question
Greetings, I have learned a lot from all of you, and I hope to over come my latest road block. I have a smal IRC Chat client I am making. I have a Dialog Box with Control and I use a worker thread for connecting to IRC - That Thread will update controls on the Dialog by sending PostMessages. Now my problem is in the ListBox Control that I have extended to do popup menu with various commands. I need to be able to read that controls methods from within the Thread. so I need to do this from within my IRC Socket thread: (code not exact - pseudo code) CListBoxEx myUsers; //Defined in my ...

excel filtering #3
how can I see how many rows meet my filter criteria in excel Use this function: SUBTOTAL(3,A2:A100) "Arthur Kuijper" wrote: > how can I see how many rows meet my filter criteria in excel Lower left hand corner of screen will say something like... '25 of 187 records found' immediately after applying the filter HTH, Gary Brown using Excel XP "Arthur Kuijper" wrote: > how can I see how many rows meet my filter criteria in excel Gary Not necessarily. From Debra Dalgleish...................... Normally, after you have applied an AutoFilter, the Status...

Need Help with Busy Dialog Thread
my application would perform a task. I want to stop the user from using the application's GUI untill the the BG task is finished. At first using Modal Dlg did not do the trick as every one now (apart from me) the the CDialog::DoModal() function has to return some how. So, I made a bit of research on the net and found a trick to display the Dialog using CWinThread derived class without stoping the main app window for executing the background task as follows: (1) In your header file define a CWinThread-derived class... class CDialogThread : public CWinThread { DECLARE_DYNCREATE(CDial...

exe files #3
I have an old e-mail from 2001 where some one had sent me a small .exe file .... now a couple of years later, I need to get that file again, how ever outlook will no longer let me get at it ... it says it is blocked ... Is there any way to get that attatchment ?? Regards, Gordon http://groups-beta.google.com/group/microsoft.public.outlook/search?group=microsoft.public.outlook&q=getexe&qt_g=1 -- Milly Staples [MVP - Outlook] Post all replies to the group to keep the discussion intact. Due to the (insert latest virus name here) virus, all mail sent to my personal account wi...

Killing thread from outside thread in MFC App
Hi, Thanks to all those who offered advise on my last query. I successfully used the worker thread method to give control back to the dialog box whilst background processing was being carried out. The issue I have now is closing that thread externally. The method I've used to create the thread uses a volatile boolean variable. Whilever it is set to TRUE, the thread remains alive. However, when I set the variable to FALSE from the calling process (user wants to end processing), it has no effect. The thread continues to run. I thought that declaring the variable as 'volatile'...

Error in CRM 3.0 trying to access My Work | Activities area
We are having a bit of trouble with one of our user accounts accessing “Workplace | My Work | Activities”. It actually they are getting the "Error: An error has occurred. For more information ..." on this page. Every other page is fine and all other users are good. Only this one user when they try to access their activities. Permissions are not the problem as the user has exactly the same as everyone else. So what else could it be? Any suggestions would be great. I have CRM 3.0 installed on Windows 2003 Enterprise with SQL 2005 Enterprise. Thats it thats all. Thanks. ...

To Thread or not to thread
I am using a CRecordset object to retrieve data from a remote server. The time to retrieve the data is highly variable because of network traffic etc etc etc and has varied from a few ms to almost a minute. Question: Is it a good practice to use a worker thread to handle the database exchange to avoid having my main thread block for long periods of time? I assume that I would let the exchange timeout and then check the return status and a global variable to determine if it should keep trying until it returned data ( might be null but that's ok). Ron H. Ron, While it may be a tin...

Permissions #3
When a user attempts to reply to a message sent from a group mailbox, she receives error ""you do not have permission to send a message on behalf of the user", this user is setup with the same permissions as other users who can reply - editor/full review. ...

Pivot Table Formula #3
Can a formula be done in one Pivot Table using a field from another pivot Table? A calculated field can only refer to fields in its own pivot table. It can't refer to other pivot tables. carolini wrote: > Can a formula be done in one Pivot Table using a field from another pivot > Table? -- Debra Dalgleish Excel FAQ, Tips & Book List http://www.contextures.com/tiptech.html ...

SMTP issue #3
Hi, I did setup virtual SMTP server on my web server, and I want to test the virtul smtp to see if I can send e-mail to out side. I did configure the outlook express, I opened a new mail and send it to a knowen address, when I click on send/receive it semas that mail had been send out side, but when I look at the Queue in mailroot all the e-mails are there. I am useing 2003 web edition, this server is in DMZ, I use netstat and port 25 is open. So I have no idea what is going on here! Any idea? Why Web edition? Which Queue is it stuck in? Does it have access to DNS? Can the Exchange serv...

Anyone care to offer advice for my Client / Server threading model
I'm a bit of a sockets newbie and not too sure what the established ways of handling CAsyncSockets are. I need to handle two way comms between two or more handheld pcs and a server. WIth the server I've got: 1 Thread polling for new connections 1 Thread per client connection. The client thread is stuck in a loop called from CWinThread::InitInstance and sits and calls the CAsyncSocket::Receive function until something arrives. It uses peekmessage and postmessage in this loop to see if the app wants me to send anything to the client. This is working erratically though - peekmessage know...

Lost files #3
I use money to keep track of my expenses and income on my rental properties. I exported the files from money 1999 to money 2004, when the files showed up on my check register it did not list the properties addresses . How do I go back into money and make sure that the addresses stay posted with each check Thank You Michael C ...

HELP #3
Hi, strange request here... My girlfriend is buying our wedding rings and the file sent to us in in Publisher. I'm hoping someone might offer to open it for me, save or export it to PDF or Word and send it back to me. We do not have Publisher and don't want to go buy it just to open one file. Any help would be appreciated. Cliff cliff@crpoe.com If the pub file was created with Pub 2000 or earlier, I'd be glad to help. -- Don ------- My real e-mail address is: dschmidtATpacifierDOTcom "Cliff" <cliff@one.com> wrote in message news:e9Gzi3n7DHA.2404@TK2MSF...

Threads in MFC
Hi to all... I've made a multithreaded Application (with MFC of course) and it works well on some PC, but in others PC's with the same OS (Win2000SP4) it throws "access Violation" immediatly just when a thread starts. (No matter which one... just the first). I've supposed it was some lib missing, and I've installed VC6... it didn't solve anything. any suggestion? I had a similar problem when I didn't realize I was trying to distribute a DEBUG version of the program. Otherwise, can you post a code snippet? On Mon, 19 Apr 2004 16:55:16 +0200, Nicola Bam...

LOG file question #3
Dear, I have 4 thousand log file since 1st June 2006. It's 5MB per each. They occupied 23 GB of the disk space already. How can I set it up purge the log file automatically? Thanks! -david Run a full online backup of Exchange using NTBackup (from the Exchange server or another server with ESM installed) or by using your backup software that has an Exchansge agent. -- Ben Winzenz Exchange MVP MessageOne Read my blog! http://winzenz.blogspot.com http://feeds.feedburner.com/winzenz (RSS Feed) "Cat bite" <Cat_bite@catz.kingdom> wrote in message news:%23WnAmgW0GHA....

multi-threaded control not destroyed on exiting the page?
I have created an ActiveX control (subclassing COleControl) which uses the afxRegFreeThreading model, and I have a small sample web page which inserts the control using an <object> tag. I noticed that when my page places the control inside the <head> tag, the control's destructor is called when my browser goes to a different page. But if the control is inside the <body> tag, the destructor is not called when I leave the page. The control's destructor is eventually called when I exit my browser, but I fear that my control is continuing to occupy system resources unt...

MAD monitoring thread?
I have Exchange 2000 running on a Win2K Server. I have a trust to an NT4 domain with an Exchange 5.5 Server. Both are in the same site and my goal is to move the mailboxes and whatnot to the Exchange 2000 box. So far, just getting 2000 to operate has been a problem. It's installed and running but my MS Exchange Info Store and MTA stacks won't start in the services. If I reboot, they start, but stop within a few minutes. I have errors in my application log for MSExchangeSA that say, "The MAD monitoring thread was unable to read its configuration from the DS." I have MSEx...

synchronization #3
Dear friends, I have a problem: I have to computers, one at office, the other at home. On both computers I use outlook intensively, in particular the calender. Now, when I make a change at the hoke computer, the one at the office remains out of date (or vice versa). And this cause problems because the two calenders contain different items, as I can not keep track of every input I make in either of the computers. So I need synchronization between the computers. But I absolutely have no idea how to do that. Here is what I was thinking: I work at the university and on the computer network I ha...

how to total 3 series in a column chart
I have a column chart with 3 series stacked on top of each other. Is there a way in this chart to indicate a combined total of the values of all 3 series at the top of the column? Hi Everyone, I need two formula's to get me going, the posible sinerios are either the student has an Absent (ABS) or he has a pass mark of between 40 - 100. while draging it down i want it to ignor the cells to the left where there is either no score or its blank i.e CELL(A1) 40 1 CELL (A2) Blank ( Ignor if no score) CELL (A3) 32 0 1. IF(O...

networkdays #3
I want to use networkdays to put together a time line, such as using starting date then adding 6 days to get the next date and so on. Wha does the formula look like for this? I tried A1 + 6 and got a date tha included the weekend. Please help.:confused -- ANY ----------------------------------------------------------------------- ANYA's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=3409 View this thread: http://www.excelforum.com/showthread.php?threadid=53871 Are you thinking of =workday(a1,6) Remember that the analysis toolpak addin must be loaded (tools|A...