Page 1 of 1

Please reuse old PureBasic thread IDs

Posted: Mon Jul 06, 2009 4:45 am
by Mistrel
If PureBasic can be expected to reuse old IDs then it would be feasible to use a single array to reference a collection of threads if the maximum number of concurrent threads is always known. Otherwise we need to use slower data structures which are not indexed or other creative but more complex solutions:

Code: Select all

Procedure This(Null)
EndProcedure

Debug CreateThread(@This(),0) ;/ 1
Debug CreateThread(@This(),0) ;/ 2
Debug CreateThread(@This(),0) ;/ 3
Debug CreateThread(@This(),0) ;/ 4
Delay(400)
Debug CreateThread(@This(),0) ;/ 5
Debug CreateThread(@This(),0) ;/ 6
Debug CreateThread(@This(),0) ;/ 7
Debug CreateThread(@This(),0) ;/ 8

Posted: Mon Jul 06, 2009 8:09 am
by Kaeru Gaman
the Thread number (PB-ID) is used for Kill, Pause, Resume... etc. yes?

can it be retrieved from inside the thread?

... just curious...

Posted: Mon Jul 06, 2009 9:34 am
by Fred
Don't assume the thread ID is linear or something. On Linux for example it's not the case.

Posted: Mon Jul 06, 2009 7:16 pm
by Mistrel
Kaeru Gaman wrote:the Thread number (PB-ID) is used for Kill, Pause, Resume... etc. yes?

can it be retrieved from inside the thread?

... just curious...
Not that I'm aware of:

http://www.purebasic.fr/english/viewtopic.php?t=38023
Fred wrote:Don't assume the thread ID is linear or something. On Linux for example it's not the case.
I expect nothing considering it doesn't work this way to begin with. However, my feature request still stands as a feature request. It would be a nice thing for PureBasic to standardize for us.

Posted: Mon Jul 06, 2009 8:05 pm
by freak
> However, my feature request still stands as a feature request. It would be a nice thing for PureBasic to standardize for us.

It used to be like that, but its problematic:

Code: Select all

a = CreateThread(@ThreadA(), 0) ; a = 123
Delay(1000)                     ; ThreadA finishes, 123 is free again   
b = CreateThread(@ThreadB(), 0) ; b = 123

WaitThread(a)                   ; We want to wait for ThreadA, but we wait for ThreadB instead which is wrong
I don't understand why you need this anyway. If you know there are never more that 5 threads, then just create an array with 5 slots for the IDs of the running threads. The actual values of the IDs do not matter for this.

Posted: Mon Jul 06, 2009 11:34 pm
by Mistrel
I hoped that by reusing old thread IDs I could match the index of an array with a thread ID. But after considering your example I understand that my idea was flawed.

Thank you for clarifying. :)