Halting Threads

BlitzMax Forums/BlitzMax Beginners Area/Halting Threads

SSS(Posted 2009) [#1]
Hi everyone,

I did a quick search of the forum and through the documentation but to no avail. I was wondering whether it was possible to stop threads once they've been started. I see that you can detach a thread but that's about it.

Thanks


Dreamora(Posted 2009) [#2]
sure, the function that you threaded just needs to return.


lukehedman(Posted 2009) [#3]
Ii haven't tried using return, which I'm guessing is much faster, but if you want to pause a thread you could create a placeholder mutex that doesn't lock any actual data, make sure the child thread requests a locking of the mutex, and have the main thread lock it beforehand.

Here's an untested code example

Child thread

Repeat

LockMutex(PlaceHolder)
UnlockMutext(PlaceHolder)

'All the thread processing goes here.

Forever

Umm... That code was so short I doubt it helped much. :-D

Ayyway, it's just an idea. Get advice from others too.


Nate the Great(Posted 2009) [#4]
if you are using a loop then try out semaphores

use waitsemaphore every loop. This way you can also sync your threads with your main program


SSS(Posted 2009) [#5]
Thanks guys... that worked really well!