Hi All
Had a chuckle when I re-read my last post;
Thanks for that badidea,
With the test example from badidea I get only one instance of the thread renamed to THREADFOO.
When I implement it into my application I get 2 instances of the renamed thread but with consecutive PID numbers.
So it looks like another thread with the same name. The Test thread also has 2 instances with the same name.
The second instance of the thread does not seem to accumulate time, it stays at 0:00:0
I guess creating multiple threads that don't run (or consume time) doesn't affect performance, but it just puzzles me.
Regards
EDIT: The ultimate aim is to set a Thread's priority using PTHREAD_SETSCHEDPARAM(3)
EDIT2:
Have modified your test as follows.
Code: Select all
'https://manpages.courier-mta.org/htmlman3/pthread_setname_np.3.html
#include "crt/pthread.bi"
Declare sub mythread1(param as any ptr)
Declare sub mythread2(param as any ptr)
Declare sub print_dots(ByRef char as string)
Dim Shared As pthread_t Ptr This_Thread
Dim Shared As Sched_param Params
Dim As pthread_t Ptr pThread1 = ThreadCreate(@mythread1, 0)
Dim As pthread_t Ptr pThread2 = ThreadCreate(@mythread2, 0)
dim As zstring * 16 threadName = "" + chr(0)
Sub print_dots(ByRef char As String)
For i As Integer = 0 To 2999
Print char;
Sleep CInt(Rnd() * 100), 1
Next
End Sub
Sub mythread1(param As Any Ptr)
Dim as Long ret, policy
print_dots("*")
End Sub
Sub mythread2(param As Any Ptr)
print_dots("-")
End Sub
Randomize(Timer())
print "1;";pthread_getname_np(*pThread1, @threadName, 16)
print "2;";threadName
print "3;";pthread_setname_np(*pThread1, !"THREADFOO\0")
print "4;";pthread_getname_np(*pThread1, @threadName, 16)
print "5;";threadName
params.sched_priority = sched_get_priority_max(SCHED_FIFO)
Print "6;";params.sched_priority
''Now you have to be Root otherwise next line fails.
Print "7;";pthread_setschedparam(*pthread1, SCHED_FIFO, @params)
print_dots(".")
ThreadWait(pThread1)
ThreadWait(pThread2)
Print
Sleep
Setting a Thread to RT works, but it is showing up on htop as Test being RT and not THREADFOO ????
EDIT3: It seems like the ps command is a bit reluctant to show detail unless you specifically request it.
top -H -p "PID #" shows the new name AND the RT priority.