Recent

Author Topic: TThreadID on Mac - insights?  (Read 1878 times)

AlanTheBeast

  • Sr. Member
  • ****
  • Posts: 348
  • My software never cras....
Re: TThreadID on Mac - insights?
« Reply #15 on: June 29, 2022, 07:53:23 pm »
Any insight into why the last three nybles of TTreadID are '0'?
Should that question be referred to Apple rather than FPC?

BeginThread is based on the underlying thread manager, which defaults to Posix Threads for Unix systems.

which in turn takes us to pthread_create function.
(eventually one might want to dig down to _pthread_allocate(), etc...)
and OS allocates whatever it considers needed for a thread. guard pages, register storage, etc.

Very good point.
In pthread I find (for Mac OS)
Code: C  [Select][+][-]
  1. #define DEFAULT_STACK_SIZE (size_t)(512 * 1024)

It could be changed at runtime or the OS could change the default (perhaps).  (Programmer can too, of course).

A bit moot for me now, as the question is for Ultibo RTL.  For that I can set the stacksize as needed for these threads (math intense, not "deep" on calls) in BeginThread...

On Mac OS, with what I assume to be a shallow stack need, I set it to $1000 --- the threads failed to start.  TThreadID returns a 0.
Code: C  [Select][+][-]
  1.         if (os_unlikely(attrs->stacksize != 0 &&
  2.                         attrs->stacksize < PTHREAD_STACK_MIN)) {
  3.                 PTHREAD_CLIENT_CRASH(attrs->stacksize, "Stack size in attrs is too small");

https://github.com/fpc/FPCSource/search?q=PTHREAD_STACK_MIN has several defs...

Set it to $2000 and it runs fine.   $1800 ... nope.

And from other bits of the pthread code I assume it adds a page worth of safety to that ...
« Last Edit: June 29, 2022, 08:21:22 pm by AlanTheBeast »
Everyone talks about the weather but nobody does anything about it.
..Samuel Clemens.

 

TinyPortal © 2005-2018