Re: [GD-Windows] Stopping a thread cleanly
Brought to you by:
vexxed72
From: Andrew G. <an...@ra...> - 2002-02-17 20:09:47
|
It's just 'better' really. One case that I can remember is this: int ThreadFunc() { while (false == bExit) { } } In this case the compiler could put bExit in a register due to optimisation which obviously isn't good. You could specify it as volatile which will prevent that, but that seems a bit ugly. And you have the cases where the compiler might rearrange the order of bExit=false; CreateThread(); // andrew ----- Original Message ----- From: "Brian Hook" <bri...@py...> To: <gam...@li...> Sent: Sunday, February 17, 2002 7:37 PM Subject: [GD-Windows] Stopping a thread cleanly > Okay, kind of a newbie question, but I thought I understood it, now I'm > not so sure. > > What are the advantages/disadvantages of exiting a thread based on > WaitForSingleObject with short timeout vs. checking a global variable? > Both are effectively in a delayed hard polling loop, where the delay is > a Sleep( 250 ). > > The only advantage I can really see is that the WFSO call is going to > avoid race conditions intrinsically, whereas checking a global variable > I'll have to be a lot more diligent about guarding accesses to the > variable. > > Brian > > > _______________________________________________ > Gamedevlists-windows mailing list > Gam...@li... > https://lists.sourceforge.net/lists/listinfo/gamedevlists-windows > Archives: > http://sourceforge.net/mailarchive/forum.php?forum_id=555 > |