> On Oct 30, 2022, at 7:20 PM, Marco van de Voort via fpc-pascal 
> <fpc-pascal@lists.freepascal.org> wrote:
> 
> I'm not that deep into those procedural threading. From what I remember the 
> prototypes are defined, but not their use.
> 
> But since tthread works on top of that, you can simply trace how tthread does 
> it, which is probably more solid and up to date than documentation and two 
> decade old tutorials.
> 
> Most notably how tthread.freeonterminate is implemented. Some OSes like 
> Windows (that tthread is modeled after) keep some thread resources around to 
> read the result back after the thread is finished.
> 
>>  Pthreads at least doesn’t appear to require you to detach the thread but 
>> maybe it’s leaking memory then.
> 
> The manual you quoted seemed to indicate you either have to call _join or 
> _detach.

Yes you’re right, I didn’t read all the way to the bottom. It says you must 
call join OR detach to free resources. That doesn’t sound right you could only 
call join but who knows..

I tried to call EndThread (which calls pthread_detach) after the function 
reaches the end but I get a crash. Looking BeginThread it appears to call the 
user callback in a wrapper and does cleanup for you but I’m not 100% clear 
about this. Docs 
(https://www.freepascal.org/docs-html/rtl/system/beginthread.html) don’t say 
you must cleanup either so I’m guessing you don’t have to.

Regards,
Ryan Joseph

_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to