Get own threadID without passing as parameter
Get own threadID without passing as parameter
Hi,
Same posts from different users have been done many times but none solved.
Is there any way to get own ThreadID from inside thread, just like ProgramFileName()?
If anyone knows that this is impossible also thanks for reply.
Same posts from different users have been done many times but none solved.
Is there any way to get own ThreadID from inside thread, just like ProgramFileName()?
If anyone knows that this is impossible also thanks for reply.
- netmaestro
- PureBasic Bullfrog
- Posts: 8433
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Re: Get own threadID without passing as parameter
Yes... Very curious. Maybe I should remove 1 of 4,7 square meter of living surface to try to understand the psychological mechanism which bring such these questions with such a sentence as << Same posts from different users have been done many times but none solved >>.
@Lik137
Yes, there is a way. I published this way obviously, and certainly I am not the alone person to publish it.
Could you give more details about the same posts from different users ?
This allows me to stamp a link in each of these post you talk about.
@Lik137
Yes, there is a way. I published this way obviously, and certainly I am not the alone person to publish it.
Could you give more details about the same posts from different users ?
This allows me to stamp a link in each of these post you talk about.
- NicTheQuick
- Addict
- Posts: 1227
- Joined: Sun Jun 22, 2003 7:43 pm
- Location: Germany, Saarbrücken
- Contact:
Re: Get own threadID without passing as parameter
On Linux it works like so:
Output:
Code: Select all
Procedure test(dummy.i)
Debug "Inside thread: " + pthread_self_()
EndProcedure
Define thread.i = CreateThread(@test(), 0)
Debug "Outside thread: " + thread
Delay(1000)
Outside thread: 139836075214592
Inside thread: 139836075214592
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
Re: Get own threadID without passing as parameter
Hello NicTheKick,
thank you for your help.
I would proceed as below x64, but I let you have the right ref.
thank you for your help.
I would proceed as below x64, but I let you have the right ref.
Code: Select all
Procedure Zot(void.Q)
Define uit.Q
! mov [p.v_uit], rax
EndProcedure
Last edited by Olliv on Thu Apr 30, 2020 9:21 pm, edited 1 time in total.
Re: Get own threadID without passing as parameter
Dear netmaestro,
Thank You for reply.
This is for passing commands from clients to server and putting into queue.
Each command is handled and put into list/map in structure
Then for each command new thread is being created.
In this thread I want to link CommandID with threadID so each thread handles it's own Command.
That is it.
Thank You for reply.
This is for passing commands from clients to server and putting into queue.
Each command is handled and put into list/map in structure
Then for each command new thread is being created.
In this thread I want to link CommandID with threadID so each thread handles it's own Command.
That is it.
Re: Get own threadID without passing as parameter
Hi NicTheQuick,
Thanks very much.
But if possible for windows.
Thanks very much.
But if possible for windows.
Re: Get own threadID without passing as parameter
Code: Select all
Structure Bus
void.i
...
EndStructure
Procedure myProc(*B.Bus)
With *B
...
EndWith
EndProcedure
Define *B.Bus
Th0 = CreateThread(@myProc(), *B)
Repeat
Delay(1)
Until *B\Quit
https://www.purebasic.fr/french/viewtop ... 66&start=4
Re: Get own threadID without passing as parameter
Dear Olliv,
Please neglect my posts, do not waste your precious time.
You will help me if you do not reply to my posts.
Thank You very much for understanding.
Please neglect my posts, do not waste your precious time.
You will help me if you do not reply to my posts.
Thank You very much for understanding.
Re: Get own threadID without passing as parameter
Code: Select all
Procedure test(dummy.i)
Debug "Inside thread: " + GetCurrentProcessId_()
Debug "Inside thread: " + GetCurrentThreadId_()
Delay(20000)
EndProcedure
Define thread.i = CreateThread(@test(), 0)
Debug "Outside thread: " + thread
Delay(25000)
Re: Get own threadID without passing as parameter
Dear infratec,
Just added "Debug "Outside2 thread: " + ThreadID(thread)" before delay(25000) to check result
results:
[00:46:53] Outside1 thread: 1
[00:46:53] Outside2 thread: 184
[00:46:53] Inside thread: 516
[00:46:53] Inside thread: 7164
Inside and Outside completely different.
Thanks very much
Just added "Debug "Outside2 thread: " + ThreadID(thread)" before delay(25000) to check result
Code: Select all
Procedure test(dummy.i)
Debug "Inside thread: " + GetCurrentProcessId_()
Debug "Inside thread: " + GetCurrentThreadId_()
Delay(20000)
EndProcedure
Define thread.i = CreateThread(@test(), 0)
Debug "Outside1 thread: " + thread
Debug "Outside2 thread: " + ThreadID(thread)
Delay(25000)
results:
[00:46:53] Outside1 thread: 1
[00:46:53] Outside2 thread: 184
[00:46:53] Inside thread: 516
[00:46:53] Inside thread: 7164
Inside and Outside completely different.
Thanks very much
Re: Get own threadID without passing as parameter
I know, but I think this is a PB bug:
There is nothing to see of 364
There is nothing to see of 364
Re: Get own threadID without passing as parameter
Is this what you mean?LiK137 wrote:Is there any way to get own ThreadID from inside thread
Code: Select all
Global id_thread_1, id_thread_2
Procedure Thread1(null)
Debug "Thread 1 ID: "+Str(id_thread_1)
EndProcedure
Procedure Thread2(null)
Debug "Thread 2 ID: "+Str(id_thread_2)
EndProcedure
id_thread_1=CreateThread(@Thread1(),0)
id_thread_2=CreateThread(@Thread2(),0)
Delay(100)
Re: Get own threadID without passing as parameter
Extended version without global variables:
Since you need (normally) always parameters, you can add them in the structure.
Code: Select all
Structure ThreadParameterStructure
Thread.i
Delay.i
EndStructure
Procedure test(*ThreadParameter.ThreadParameterStructure)
Debug "CurrentProcessId: " + GetCurrentProcessId_()
Debug "CurrentThreadId : " + GetCurrentThreadId_()
;Debug "CurrentThread : " + GetCurrentThread_()
Delay(*ThreadParameter\Delay)
EndProcedure
Define ThreadParameter.ThreadParameterStructure
ThreadParameter\Delay = 20000
ThreadParameter\Thread = CreateThread(@test(), @ThreadParameter)
Debug "Outside Thread: " + ThreadParameter\Thread
Debug "Outside ThreadID: " + ThreadID(ThreadParameter\Thread)
Delay(25000)
Re: Get own threadID without passing as parameter
Dear infratec,
I agree with You regarding the real thread obtained by GetCurrentThreadId_()
But how to use this ThreadID with PureBasic thread library to check if running or pause or kill.
With Purebasic ThreadID() it is possible to pause or kill or check if thread running.
Thank You very much
I agree with You regarding the real thread obtained by GetCurrentThreadId_()
But how to use this ThreadID with PureBasic thread library to check if running or pause or kill.
With Purebasic ThreadID() it is possible to pause or kill or check if thread running.
Thank You very much