Please reuse old PureBasic thread IDs

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Please reuse old PureBasic thread IDs

Post 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
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post 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...
oh... and have a nice day.
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

Don't assume the thread ID is linear or something. On Linux for example it's not the case.
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

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

Post 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.
quidquid Latine dictum sit altum videtur
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

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