WaitForThread() ... Simple and Easy.

Share your advanced PureBasic knowledge/code with the community.
Shannara
Addict
Addict
Posts: 1808
Joined: Thu Oct 30, 2003 11:19 pm
Location: Emerald Cove, Unformed

WaitForThread() ... Simple and Easy.

Post 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)
freak
PureBasic Team
PureBasic Team
Posts: 5944
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

PB has a WaitThread() command (since a long time), that is even more CPU efficient than your code.
quidquid Latine dictum sit altum videtur
Shannara
Addict
Addict
Posts: 1808
Joined: Thu Oct 30, 2003 11:19 pm
Location: Emerald Cove, Unformed

Post by Shannara »

ooooo, figured I must of by passed it.
Bonne_den_kule
Addict
Addict
Posts: 841
Joined: Mon Jun 07, 2004 7:10 pm

Post by Bonne_den_kule »

lol, trying to reinvent the wheel, shannara?
:P
Shannara
Addict
Addict
Posts: 1808
Joined: Thu Oct 30, 2003 11:19 pm
Location: Emerald Cove, Unformed

Post 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.
Post Reply