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

Improve signal handler #18

Open
elfring opened this issue Jun 8, 2015 · 2 comments
Open

Improve signal handler #18

elfring opened this issue Jun 8, 2015 · 2 comments

Comments

@elfring
Copy link

elfring commented Jun 8, 2015

The variable "threads_on_hold" should use the data type "sig_atomic_t", shouldn't it?

@Pithikos
Copy link
Owner

Pithikos commented Jun 9, 2015

Hi elfring and thanks for the feedback. I don't think an atomic operation is really needed in this case. The reason is that only one the main thread is supposed to change the boolean ´threads_on_hold´. Thus I would think that there is not any problem with having it as a normal variable.

I can think only of one scenario that might be an issue; when the main program has more than one threads. Still, realistically, I can't imagine that being a big problem:

  • If two threads they both set the boolean to 0, then there is no problem. The second thread re-setting the boolean is actually not changing anything.
  • If two threads they both set the boolean to 1, then there is no problem. The second thread re-setting the boolean is actually not changing anything.
  • If one sets the boolean to 0 and the other to 1 still there is no problem. The reason is that the boolean will be set to either one of the two and thus one of the two threads is correct. In such a case it's more of a program design issue and I would look more into that.

If you think I missed something, feel free to comment.

@elfring
Copy link
Author

elfring commented Jun 10, 2015

An atomic update will be needed in your implementation because the mentioned variable is used for data exchange within a signal handler.
Thus I would appreciate that a data type definition which is recommended for such a purpose will be reused.

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

No branches or pull requests

2 participants