Recent

Author Topic: pthread_cleanup_push analog  (Read 1959 times)

DevilDevil

  • New Member
  • *
  • Posts: 49
pthread_cleanup_push analog
« on: June 02, 2020, 07:25:52 pm »
I am developing a memory manager. The core is in C (Clang), and the API binding will be in the final language. Now it’s Delphi/FreePascal, then there will be headers for C/C++ companion compilers.

There is one important feature. At some moment, my function is called from an arbitrary thread created by someone in some language. At this moment, I need to register the callback thread to complete in order to properly clean it.

On Windows, I do this with fiber. I googled POSIX, they say there is pthread_cleanup_push.

But firstly, we do not have this macro in the headers. Secondly, apparently, he is obliged to work in tandem with pthread_cleanup_pop, i.e. is temporary: https://godbolt.org/z/FB564h

All I found are two functions:
https://www.man7.org/linux/man-pages/man3/pthread_setcancelstate.3.html
https://www.man7.org/linux/man-pages/man3/pthread_setcanceltype.3.html

But nowhere is it visible how you can specify a callback
Please tell me what to do

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 9686
  • FPC developer.
Re: pthread_cleanup_push analog
« Reply #1 on: June 02, 2020, 10:35:50 pm »
Look at the headers of the multiple supported *nixes.

Manpages are often simplified.

DevilDevil

  • New Member
  • *
  • Posts: 49
Re: pthread_cleanup_push analog
« Reply #2 on: June 02, 2020, 11:08:56 pm »
Look at the headers of the multiple supported *nixes.

It is too difficult for me: https://code.woboq.org/gcc/include/pthread.h.html#574

DevilDevil

  • New Member
  • *
  • Posts: 49
Re: pthread_cleanup_push analog
« Reply #3 on: June 04, 2020, 11:06:37 am »
I heard that FPC can finalize threadvar.
I need similar functionality. But in the source I did not find the corresponding code. Can we attract FPC developers?

PascalDragon

  • Hero Member
  • *****
  • Posts: 3492
  • Compiler Developer
Re: pthread_cleanup_push analog
« Reply #4 on: June 04, 2020, 11:21:46 am »
All threadvar related functionality for pthreads is located inside rtl/unix/cthreads.pp.

 

TinyPortal © 2005-2018