which I suspect is the normal behaviour? But even if I pause it immediately,
I still sometimes get an error because the thread has started before the
PauseThread command has kicked in. So maybe CreateThread could have
another flag to tell it pause the thread when created? Here's some code
which demonstrates my problem:
Code: Select all
Global th
Procedure MyThread()
Repeat
Debug "Thread"
PauseThread(th)
ForEver
EndProcedure
th=CreateThread(@MyThread(),0)
If th=0 : End : Else : PauseThread(th) : EndIf
Debug "Main loop"
Repeat : Sleep_(1) : ForEver
which is great. But occasionally, you'll see "Thread" there first, because
the thread has started before PauseThread in the If/EndIf check is done.
This causes my app to crash, because the thread is trying to do something
when my Main Loop isn't ready yet... even though I've paused the thread
immediately after creating it.

So, I was thinking, maybe we could have an optional flag to pause the
thread as soon as it's created, to prevent this happening? Perhaps like:
Code: Select all
th=CreateThread(@MyThread(),0,#PB_Thread_Paused)
too? Like: #PB_Thread_Low, #PB_Thread_BelowNormal, #PB_Thread_Normal,
#PB_Thread_AboveNormal, #PB_Thread_High, #PB_Thread_RealTime?
So to create a new thread that's paused upon creation with a high priority:
Code: Select all
th=CreateThread(@MyThread(),0,#PB_Thread_Paused|#PB_Thread_High)

EDIT: Okay, I know I can easily just do it like this...
Code: Select all
Procedure MyThread()
Repeat
PauseThread(th)
Debug "Thread"
ForEver
EndProcedure
think of any), so if it's easy enough to put in, yeah, go for it.

put in the priority flags?
