Skip to content
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

Merged
merged 13 commits into from
Jun 7, 2017

Conversation

jbboehr
Copy link

@jbboehr jbboehr commented Jun 1, 2017

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 calling zookeeper_dispatch(), by using declare(ticks=1), or, in PHP 7.1 or greater, automatically using VM interrupts.

@coveralls
Copy link

coveralls commented Jun 1, 2017

Coverage Status

Coverage decreased (-19.7%) to 58.215% when pulling df26ce0 on thread-cb-issue-2 into d400640 on master.

@Timandes
Copy link
Member

Timandes commented Jun 1, 2017

👍

@coveralls
Copy link

coveralls commented Jun 1, 2017

Coverage Status

Coverage increased (+6.2%) to 84.07% when pulling 2649dd0 on thread-cb-issue-2 into d400640 on master.

@jbboehr
Copy link
Author

jbboehr commented Jun 1, 2017

Looks like the oneshot parameter is not currently working, and the internal callbacks may no longer be needed - requires some further review/work.

p->cb_data = cb_data;

// Add to list
if( ZK_G(head) && ZK_G(tail) ) {
Copy link
Member

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?

Copy link
Author

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.

@coveralls
Copy link

coveralls commented Jun 7, 2017

Coverage Status

Coverage increased (+5.7%) to 83.623% when pulling 6065f75 on thread-cb-issue-2 into d400640 on master.

@coveralls
Copy link

coveralls commented Jun 7, 2017

Coverage Status

Coverage increased (+5.7%) to 83.623% when pulling 6065f75 on thread-cb-issue-2 into d400640 on master.

@Timandes Timandes merged commit 040c968 into master Jun 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

php example watch callback cause segmentation fault frequently,but sometimes success
3 participants