Forgive me for disagreeing. The original question was how you could
terminate a systemthread without using events. If you could use an
event it would be a very nice and clean solution, but apparently for
some unknown reason we cannot do this. This leads to looping
on a variable which is then set from another thread. I imagine a
setting like this:
SystemThread:
while (bTerminate)
{
…
}
TerminateMySelf();
ControlThread/callback/whatever:
if (SysThreadShouldTerminate)
bTerminate = TRUE;
Weather or not the access to bTerminate needs to be an atomic
operation or not is architechture dependant. And nice code is
architecture independant thus you should synchronize and the typical
choice would be the InterLocked functions. The oneway street approach
is flawed. The the real question is could it be that the variable is
read and written to at the same time? And regardless if one thread is
just read and the other is just writting this could occour.
Regards,
Anders
Friday, May 18, 2001, 11:08:15 AM, you wrote:
RM> If your writer writes the location and then sets the event, your reader will
RM> either wake up and then do the read AFTER the write occurs, or will have
RM> already woken up for some other reason, do the read BEFORE the write occurs,
RM> but then when your reader does a wait on your event, it will still be set,
RM> and consequently your reader will wake up and do the read AFTER the write.
RM> You do not need an interlocked operation here, nor would it help.
RM> -----Original Message-----
RM> From: rajinder sharma [mailto:xxxxx@hotmail.com]
RM> Sent: Friday, May 18, 2001 1:24 PM
RM> To: NT Developers Interest List
RM> Subject: [ntdev] Re: Re[2]: terminating a system thread
RM> But what about if the read (in thread_A) and write (in thread_B) are
RM> occuring at the same time on this variable?
>If you use it as a ‘one way street’, that means the thread that reads
>it will never write to it and other threads that write to it will never
>read it than you need no protection !
RM> _________________________________________________________________________
RM> Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.
RM> —
RM> You are currently subscribed to ntdev as: xxxxx@stratus.com To
RM> unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com
RM> —
RM> You are currently subscribed to ntdev as: xxxxx@flaffer.com
RM> To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com
–
Best regards,
Anders mailto:xxxxx@flaffer.com
You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com