-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Add TSRM free thread handlers #15522
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Add TSRM free thread handlers #15522
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks nice to me :-)
This sounds sensible to me, but I don't really know TSRM |
I would go for the GINIT/GSHUTDOWN approach honestly, I don't like that observers show up everywhere in the engine and cause troubles. |
That's what I'll need to do for older versions, but I can't shake the feeling that it's a workaround rather than a proper solution.
Is there something specific about this PR that raises that worry, or is it more of a general thing? I don't really know much about TSRM, I just noticed this missing piece and added it because it worked for my needs. However, there might be something I’m overlooking from a technical perspective, hence my question. |
The TSRM is meant to be separate from the PHP core and the extensions. Observers are something that are currently integrated into the engine and I believe they should not bleed over into a transparent resource/threading layer. |
@nielsdos I agree on the topic of Datadog, and that's why I haven't merged it right away. I do however disagree that TSRM shall be separate. TSRM is the threading abstraction of PHP, so to observe threads, one shall observe the TSRM. There are more potential places (e.g. frankenphp uses TSRM directly) where threads are spawned, which are not hookable. We personally don't exactly mind this not being accepted - after all, we do have a workaround. I just suggested doing it, for completeness as TSRM has a start handler, but somehow no end handler. And it is, I think, less hacky than abusing GSHUTDOWN (whose role is rather destroying globals than doing end-of-thread handling specifically). |
The thing is that neither the PHP core nor TSRM create the thread, it's the server that does it, which is part of why I feel weird about this. |
Because we want to observe specifically threads used for PHP execution. As to why: recording when a specific thread id stops being used. |
I'm sorry for jumping in the middle of conversation here. Please let's also move TSRM already in the Zend engine and delete the TSRM directory. This was a plan for years and it got forgotten due to messy PHP organization. |
Hey folks,
I needed to observe new thread initialisation and found (thanks to the help of @bwoebi) that there are
tsrm_set_new_thread_begin_handler
andtsrm_set_new_thread_end_handler
functions that I could use. Now I see that there is no handler for when the thread gets freed (and joined), just atsrm_set_shutdown_handler
for when the TSRM shuts down.This PR aim is to add the missing free thread handlers.
Alternative considered: I am working on an extension that does not have globals, so
globals_ctor
andglobals_dtor
won't be called, I could fake create globals that I do not use in order to getGINIT
/GSHUTDOWN
working, but that seems just wrong, although technically working 😉