-
Notifications
You must be signed in to change notification settings - Fork 50
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
Fix segmentation fault due to improperly implemented threading #13
Conversation
👍 |
Looks like the |
p->cb_data = cb_data; | ||
|
||
// Add to list | ||
if( ZK_G(head) && ZK_G(tail) ) { |
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.
If we are using NTS version of PHP, is this ZK_G
safe enough to access the global variable head
N tail
?
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.
I not sure NTS vs ZTS matters too much here, I believe ZTS is mainly required for environments where PHP is being run within many threads in the same process. [1]
I was considering adding a mutex to this block, but as there were none in pcntl, and portability may be an issue, I did not.
The pcntl extension may be a bit different, I guess signals probably use software interrupts instead of threads.
In any case, the conservative option would be to add a mutex here.
This PR is intended to fix #8 by re-implementing the execution of callbacks passed to libzookeeper via the method used by the
pcntl
extension. Previously, callbacks would be executed in the thread started by zookeeper. Now callbacks will be executed in the original PHP thread either when callingzookeeper_dispatch()
, by usingdeclare(ticks=1)
, or, in PHP 7.1 or greater, automatically using VM interrupts.