How to synchronously wait for pangofc-fontmap.c worker thread during shutdown?

I’m working on a Pango extension for PHP and ran into a race condition that occasionally causes a segfault during PHP process shutdown. From my analysis so far, I see that the issue is related to the asynchronous worker thread started in pangofc-fontmap.c.

Currently I use usleep(50000) as a workaround to wait for the thread, but this is unreliable. Is there a way to:

  • Synchronously wait for the thread to complete

  • Test whether the thread has terminated

  • Properly coordinate shutdown to avoid the race condition

Any guidance on the proper cleanup sequence would be appreciated.

I work against Pango 1.56.3 on Ubuntu 25.10 in a docker container.

Hi,

There seems to be a PangoFc.FontMap.shutdown API for this kind of usecase, it will send a FC_END event to terminate the thread.

Hi @gwillems

thanks for your input.

It is my understanding that the shutdown function adds FC_END to the async queue of the background thread but does not actually wait for the thread being terminated.

Do you happen to know if that is correct?

I tried to use this function but still got the race condition and hence segfaults.