Re: Suspending Threads



On Sun, 08 Apr 2007 17:10:16 -0700, Dave <fairydave@xxxxxxxxxxx> wrote:

[...] From what I can tell both Peter
Ritchies code and mine have the thread determining where and when to begin waiting, so presumably the only difference between them would be
coder preference.

For what it's worth, I don't find that to be the only difference. In particular, the Interrupt method a) requires that you have a reference to the Thread object (not always the case) and b) causes an exception to occur in the thread.

IMHO it's this latter aspect that is the bigger problem. With either of the other two methods (mutex or event), the code simply sits and waits, and then continues normally when signaled. With Interrupt, you need to handle the exception and somehow re-enter the code that should be doing the work.

So while I agree that all three methods can accomplish essentially the same thing, I find that using Sleep/Interrupt is significantly inferior to the other two methods. That is, if the point is simply to introduce a point at which the code pauses and then resumes, Sleep/Interrupt breaks that model by forcing the code to exit the block and re-enter later. It's my opinion that creating a wait object is far less of an issue than forcing the code into a mold that isn't really appropriate.

I think Sleep/Interrupt would be more useful in situations where you don't have an infinite sleep time and in which the normal situation is that the sleep runs for the full time. In that case, using Interrupt to create an exception would make more sense because, well...interrupting the thread would actually be the exceptional case in that situation.

For what it's worth, I also don't see mutex and event as being exactly equivalent, since the event is more a matter of signaling, while the mutex is an ongoing thing. In other words, I would use an event where I simply need to wake a thread up and let it continue processing, and a mutex where I have some resource that needs to be protected while a single thread operates on it.

Pete
.



Relevant Pages

  • Re: Vectored Interrupt Fetch
    ... It is not just the interrupt vector ... We had a separate exception location for UTLBMISS, ... The other exceptions and interrupts trapped to a common locaiton, ... jump commoncode ...
    (comp.arch)
  • Re: Nette Features in C# 3.0
    ... 'normaler Interrupt' auseinanderdividert. ... heisst sie 'exception' und nicht 'interrupt'. ... >> diese 'Ausnahme' eben auch nur 'in Ausnahmen-Situationen' haben zu ...
    (de.comp.lang.misc)
  • Re: Nette Features in C# 3.0
    ... beschreibt 'exception' die Operation ... the interrupt mechanism ignores the exceptions that ... Solange ein Programm tut, was ich von ihm erwarte, interessiert mich ... Dass man mit kaputter Hardware schlecht kaputte Hardware testen kann, ...
    (de.comp.lang.misc)
  • Re: nasm segment directive
    ... To determine what the "native" behavior of the FPU is, we could design a bootsector to test the behavior. ... There's a thread on clax about "Floating Point Exception" - a guy did an ordinary "div cl" without clearing ah. ... I rebuilt the library with "DEBUG" defined, it informed me that the interrupt routine wasn't in ROM... ... Maybe dos is hooking int 10h. ...
    (alt.lang.asm)
  • Re: Nette Features in C# 3.0
    ... Begriffe dort gebraucht werden, beschreibt 'exception' die Operation ... der Hardware und 'interrupt' die dadurch ausgeloeste Operation einer ... Software (Beispiel: 'External and Decrementer are maskable interrupts ... Ein weiteres Beispiel fuer ...
    (de.comp.lang.misc)