WinThreadManager not consistently used lazarus / 64-FPC development ---------------------------------------------------------------------- Bi0T1N · 2020-04-07 20:25 Hello, I've had a look into the ThreadManager mechanism because I thought about implementing thread naming as TThread.NameThreadForDebugging doesn't do anything yet. However, I have some questions now: 1. The WinThreadManager is initialized through the TLS callback (regarding comments in system.pp) or directly in system.pp by following statement Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i if not Assigned(CurrentTM.BeginThread) then while the default used startup TThreadManager is in inc/thread.inc (as far as I've understood) and always sets Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i BeginThread            : @NoBeginThread;so how can it be nil? 2. Why is Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i ThreadSetPriority      :=@SysThreadSetPriority; defined and then not used in win/tthread.inc. It uses the WinAPI function name Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TThread.SetPriority(Value: TThreadPriority);begin  SetThreadPriority(FHandle, Priorities[Value]);end;directly instead of the function assigned to the WinThreadManager (ThreadSetPriority) which points to SysThreadSetPriority. This is an inconsistency compared to the other platforms (SetPriority is just one example I've picked). Is there any special reason for this inconsistency? ---------------------------------------------------------------------- Fred vS · 2020-04-07 20:51 Hello. I fear that thread.priority is not yet implemented. In cthreads.pp Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function  CThreadSetPriority (threadHandle : TThreadID; Prio: longint): boolean; {-15..+15, 0=normal}    begin      {$Warning ThreadSetPriority needs to be implemented}      result:=false;    end;    function  CThreadGetPriority (threadHandle : TThreadID): Integer;    begin      {$Warning ThreadGetPriority needs to be implemented}      result:=0;    end; Changing thread priority needs root access for Linux and FreeBSD. It seems that for Windows 10 now you need administrator access to change it: https://docs.microsoft.com/en- us/windows/win32/api/processthreadsapi/nf-processthreadsapi- setthreadpriority#remarks Fre;D ---------------------------------------------------------------------- marcov · 2020-04-07 21:13 Priority afaik was windows only. It could be that later a threadmgr one was added, but windows was not changed. The other one seems to indeed have the assigned because one route might be earlier than the other. But that initialization of inc/thread.inc is under $ifndef DISABLE_NO_THREAD_MANAGER and win32/system.pp defines DISABLE_NO_THREAD_MANAGER So that means that the variable is uninitialized, and since windows zeroes memory on startup unassigned. ---------------------------------------------------------------------- PascalDragon · 2020-04-08 08:31 Quote from: Fred vS on April 07, 2020, 10:51:19 pmI fear that thread.priority is not yet implemented. It's implemented on Windows (see the excerpt mentioned by Bi0T1N). Quote from: Fred vS on April 07, 2020, 10:51:19 pmhanging thread priority needs root access for Linux and FreeBSD. Only when you want to have realtime priority. Quote from: Fred vS on April 07, 2020, 10:51:19 pmIt seems that for Windows 10 now you need administrator access to change it: https://docs.microsoft.com/en- us/windows/win32/api/processthreadsapi/nf-processthreadsapi- setthreadpriority#remarks I can't see that mentioned anywhere. Please quote it where you think that is the case. ---------------------------------------------------------------------- Bi0T1N · 2020-04-08 09:30 Quote from: marcov on April 07, 2020, 11:13:42 pmPriority afaik was windows only. It could be that later a threadmgr one was added, but windows was not changed. Seems like that priority is an exception because of the TThreadPriority type in Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TThread.SetPriority(Value: TThreadPriority);while the default method in inc/thread.inc uses Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function  ThreadSetPriority (threadHandle : TThreadID; Prio: longint): boolean;begin  Result:=CurrentTM.ThreadSetPriority(ThreadHandle,Prio);end;However, it could call ThreadSetPriority in SetPriority for consistency (like unix/cthreads does). Quote from: marcov on April 07, 2020, 11:13:42 pmBut that initialization of inc/thread.inc is under $ifndef DISABLE_NO_THREAD_MANAGER and win32/system.pp defines DISABLE_NO_THREAD_MANAGER Oh yes, you're absolutely right. I've overlooked that define. Quote from: PascalDragon on April 08, 2020, 10:31:11 amQuote from: Fred vS on April 07, 2020, 10:51:19 pmhanging thread priority needs root access for Linux and FreeBSD. Only when you want to have realtime priority. You can instead set the niceness with the setpriority function but Quote According to POSIX, the nice value is a per-process setting. However, under the current Linux/NPTL implementation of POSIX threads, the nice value is a per-thread attribute: different threads in the same process can have different nice values. Portable applications should avoid relying on the Linux behavior, which may be made standards conformant in the future. http://man7.org/linux/man-pages/man2/setpriority.2.htmlBut as it's like this for many years now I don't think that they will ever change that. Seems more like it's intended.