[proxy] web.archive.org← back | site home | direct (HTTPS) ↗ | proxy home | ◑ dark◐ light
/ cpython Public
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

bpo-30808: Use _Py_atomic API for concurrency-sensitive signal state #2417

Merged
merged 6 commits into from Jul 17, 2017

Conversation

Copy link
Member

pitrou commented Jun 26, 2017

Based on PR #2415.

pitrou added 4 commits Jun 26, 2017
Avoid using Py_AddPendingCall from signal handler, to avoid calling signal-unsafe functions.
Copy link
Member Author

pitrou commented Jun 26, 2017

To be frank I'm not sure if _Py_atomic_int is necessary for Handlers[...].tripped, since is_tripped accesses should now act as full memory fences. But I guess better safe than sorry.

pitrou changed the title [WIP] Use _Py_atomic API for concurrency-sensitive signal state Use _Py_atomic API for concurrency-sensitive signal state Jun 29, 2017
pitrou added the type-feature A feature request or enhancement label Jun 29, 2017
Copy link
Member Author

pitrou commented Jun 29, 2017

@Haypo any concerns here?

Copy link
Member

vstinner commented Jun 29, 2017

@Haypo any concerns here?

I disagree with the "trivial" label. You need to add a bpo number. I don't understand the rationale of using an atomic type, can you please elaborate?

Copy link
Member

vstinner commented Jun 29, 2017

Based on PR #2415.

I don't see a direct link with this PR. Is it required to fix PR #2415?

Copy link
Member Author

pitrou commented Jun 29, 2017

"Based on" just means it contains the changes from that PR. Now that it's merged, it doesn't matter anymore.

Copy link
Member Author

pitrou commented Jun 29, 2017

I disagree with the "trivial" label.

There is no "trivial" label :-)

I don't understand the rationale of using an atomic type, can you please elaborate?

"Atomic" types are needed for proper interaction between concurrent running portions of code that don't use locks. Imagine trip_signal() in one thread and PyErr_CheckSignals() in another thread, for example.

We already use them in ceval.c for similar purposes.

pitrou changed the title Use _Py_atomic API for concurrency-sensitive signal state bpo-30808: Use _Py_atomic API for concurrency-sensitive signal state Jun 29, 2017
Copy link
Member

vstinner commented Jun 29, 2017

Ah, thanks for the link to http://bugs.python.org/issue30808

Copy link
Member Author

pitrou commented Jun 30, 2017

@cf-natali, I'd like your advice here.

Copy link
Contributor

Paxxi commented Jul 9, 2017

I'm thinking a lock would be better here, atomics are great for a single flag variable or ref count. In this case there's an array of flags and another thread might change tripped before it's set to 0 and losing a signal or several?

I haven't dug into how this code is called so it may be a non-issue.

Copy link
Member Author

pitrou commented Jul 9, 2017

Unfortunately, locks can't be used in signal-handling code.

Copy link
Contributor

Paxxi commented Jul 10, 2017

ahh right. Then this is a clear improvement over the current situation, 👍

pitrou merged commit 2c8a5e4 into python:master Jul 17, 2017
pitrou deleted the signal_pyatomic branch Jul 17, 2017
pitrou added a commit to pitrou/cpython that referenced this pull request Aug 6, 2017
…state (pythonGH-2417)

* Improve signal delivery

Avoid using Py_AddPendingCall from signal handler, to avoid calling signal-unsafe functions.

* Remove unused function

* Improve comments

* Use _Py_atomic API for concurrency-sensitive signal state

* Add blurb
(cherry picked from commit 2c8a5e4)
pitrou added a commit that referenced this pull request Aug 6, 2017
…state (GH-2417) (#3007)

* Improve signal delivery

Avoid using Py_AddPendingCall from signal handler, to avoid calling signal-unsafe functions.

* Remove unused function

* Improve comments

* Use _Py_atomic API for concurrency-sensitive signal state

* Add blurb
(cherry picked from commit 2c8a5e4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-feature A feature request or enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants