Page 1 of 1

WaitForThread() ... Simple and Easy.

Posted: Sat Feb 25, 2006 7:15 pm
by Shannara
Code updated For 5.20+

During my use of the hazard threading section of PB, there are times where I have to wait until a thread is finished before the program continues. Granted, at first, you may think, hey! Just use procedures ... however ...

Say you started a thread in the beginning of the program (such as listening on a certian port), and it runs during the course of your program, then during shutdown, you need to set the thread's shutdown flag, and then wait for the thread to shut down .... this code would be useful as you wouldnt want any thread leaks ...

Code: Select all

Procedure WaitForThread(Thread.l, Wait.l)
  Repeat
    Delay(Wait)
  Until IsThread(Thread) = #False
EndProcedure
Use:

Code: Select all

WaitForThread(Thread, 100)

Posted: Sat Feb 25, 2006 8:22 pm
by freak
PB has a WaitThread() command (since a long time), that is even more CPU efficient than your code.

Posted: Sat Feb 25, 2006 8:35 pm
by Shannara
ooooo, figured I must of by passed it.

Posted: Sat Feb 25, 2006 11:36 pm
by Bonne_den_kule
lol, trying to reinvent the wheel, shannara?
:P

Posted: Sun Feb 26, 2006 12:01 am
by Shannara
With 2D engines, you have to ;) I dont know how I bypassed that command, it's even in the help file! Aaahhh! Oh well, I stopped using threading until final comes out (and hopefully fixes). But I decided to post this just in case people are still trying to use threading :)

But it seems all for naught! Today must be saturday .. those and mondays are always bad days.