Just starting out? Need help? Post your questions and find answers here.
-
infratec
- Always Here

- Posts: 7618
- Joined: Sun Sep 07, 2008 12:45 pm
- Location: Germany
Post
by infratec »
Hi,
in an other thread something strange occured:
Code: Select all
Procedure test(dummy.i)
Debug "CurrentProcessId: " + GetCurrentProcessId_()
Debug "CurrentThreadId : " + GetCurrentThreadId_()
;Debug "CurrentThread : " + GetCurrentThread_()
Delay(20000)
EndProcedure
Define Thread.i = CreateThread(@test(), 0)
Debug "Outside Thread: " + ThreadParameter\Thread
Debug "Outside ThreadID: " + ThreadID(ThreadParameter\Thread)
Delay(25000)
Results in:
There is nothing to see of 364
Is it a bug, or what exactly returns ThreadID()
PB 5.72 x86 Win10 x64
Last edited by
infratec on Fri May 01, 2020 9:59 am, edited 1 time in total.
-
netmaestro
- PureBasic Bullfrog

- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Post
by netmaestro »
The OS knows what it is. If we pass the result of PB's ThreadID() function to the OS to do something with, it happens:
Code: Select all
Procedure ThisIsAThread(void)
Repeat
Debug "I'm a thread!"
Delay(1000)
ForEver
EndProcedure
tid = CreateThread(@ThisIsAThread(), 0)
Delay(2000)
tid2 = ThreadID(tid)
If TerminateThread_(tid2, 13)
Debug "No you're not..."
EndIf
Delay(5000)
GetExitCodeThread_(tid2, @exitcode.i)
Debug exitcode
BERESHEIT
-
freak
- PureBasic Team

- Posts: 5940
- Joined: Fri Apr 25, 2003 5:21 pm
- Location: Germany
Post
by freak »
It is a handle to the thread, just like ImageID() returns an image handle. The documentation mentions this.
quidquid Latine dictum sit altum videtur
-
Shardik
- Addict

- Posts: 2060
- Joined: Thu Apr 21, 2005 2:38 pm
- Location: Germany
Post
by Shardik »
freak wrote:It is a handle to the thread, just like ImageID() returns an image handle. The documentation mentions this.
I am just a moment too late. Please see my example in
this thread.
-
infratec
- Always Here

- Posts: 7618
- Joined: Sun Sep 07, 2008 12:45 pm
- Location: Germany
Post
by infratec »
@Freak : Thank you
Here is the right interpretation:
Code: Select all
Import ""
GetThreadId.l(Handle.i)
EndImport
Procedure test(dummy.i)
Debug "CurrentProcessId : " + GetCurrentProcessId_()
Debug "CurrentThreadId : " + GetCurrentThreadId_()
Debug "Virtual CurrentThread : " + GetCurrentThread_()
Debug "CurrentThreadId by OS via virtual CurrentThread : " + GetThreadID(GetCurrentThread_())
Delay(20000)
EndProcedure
Define Thread.i = CreateThread(@test(), 0)
Debug "Outside Thread: " + Thread
Debug "Outside ThreadID PB (not the ThreadID, only a HANDLE) : " + ThreadID(Thread)
Debug "Outside ThreadID OS: " + GetThreadID(ThreadID(Thread))
Delay(25000)