Skip to content

Conversation

@pitrou
Copy link
Member

Based on PR #2415.

pitrou added 4 commits June 26, 2017 19:16
@pitrou
Copy link
MemberAuthor

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.

@pitroupitrou changed the title [WIP] Use _Py_atomic API for concurrency-sensitive signal stateUse _Py_atomic API for concurrency-sensitive signal stateJun 29, 2017
@pitroupitrou added the type-feature A feature request or enhancement label Jun 29, 2017
@pitrou
Copy link
MemberAuthor

@Haypo any concerns here?

@vstinner
Copy link
Member

@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?

@vstinner
Copy link
Member

Based on PR #2415.

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

@pitrou
Copy link
MemberAuthor

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

@pitrou
Copy link
MemberAuthor

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.

@pitroupitrou changed the title Use _Py_atomic API for concurrency-sensitive signal statebpo-30808: Use _Py_atomic API for concurrency-sensitive signal stateJun 29, 2017
@vstinner
Copy link
Member

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

@pitrou
Copy link
MemberAuthor

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

@Paxxi
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.

@pitrou
Copy link
MemberAuthor

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

@Paxxi
Copy link
Contributor

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

@pitroupitrou merged commit 2c8a5e4 into python:masterJul 17, 2017
@pitroupitrou deleted the signal_pyatomic branch July 17, 2017 10:25
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 freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type-featureA feature request or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@pitrou@vstinner@Paxxi@the-knights-who-say-ni