
This issue trackerhas been migrated toGitHub, and is currentlyread-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.
Created on2017-10-01 01:43 byDaniel Colascione, last changed2022-04-11 14:58 byadmin. This issue is nowclosed.
| Pull Requests | |||
|---|---|---|---|
| URL | Status | Linked | Edit |
| PR 4078 | merged | pitrou,2017-10-22 10:45 | |
| PR 4091 | merged | vstinner,2017-10-23 17:34 | |
| Messages (4) | |||
|---|---|---|---|
| msg303441 -(view) | Author: Daniel Colascione (Daniel Colascione) | Date: 2017-10-01 01:43 | |
Right now, the main loop in semlock_acquire looks like this: do { Py_BEGIN_ALLOW_THREADS if (blocking && timeout_obj == Py_None) res = sem_wait(self->handle); else if (!blocking) res = sem_trywait(self->handle); else res = sem_timedwait(self->handle, &deadline); Py_END_ALLOW_THREADS err = errno; if (res == MP_EXCEPTION_HAS_BEEN_SET) break; } while (res < 0 && errno == EINTR && !PyErr_CheckSignals());Here, we unconditionally release the GIL even we could acquire the mutex without blocking! As a result, we could end up switching to another thread in the process and greatly increasing the latency of operations that lock and release multiple shared data structures.Instead, we should unconditionally try sem_trywait, and only then, if we want to block, release the GIL and try sem_wait or sem_timedwait. This way, we'll churn only when we need to.Note that threading.Lock works the way I propose. | |||
| msg303449 -(view) | Author: Serhiy Storchaka (serhiy.storchaka)*![]() | Date: 2017-10-01 06:11 | |
Looks reasonable to me. Do you want to provide a patch Daniel? | |||
| msg304742 -(view) | Author: Antoine Pitrou (pitrou)*![]() | Date: 2017-10-22 11:10 | |
New changesetc872d39d324cd6f1a71b73e10406bbaed192d35f by Antoine Pitrou in branch 'master':bpo-31653: Don't release the GIL if we can acquire a multiprocessing semaphore immediately (#4078)https://github.com/python/cpython/commit/c872d39d324cd6f1a71b73e10406bbaed192d35f | |||
| msg304840 -(view) | Author: STINNER Victor (vstinner)*![]() | Date: 2017-10-23 20:57 | |
New changeset828ca59208af0b1b52a328676c5cc0c5e2e999b0 by Victor Stinner in branch 'master':bpo-31653: Remove deadcode in semlock_acquire() (#4091)https://github.com/python/cpython/commit/828ca59208af0b1b52a328676c5cc0c5e2e999b0 | |||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:58:53 | admin | set | github: 75834 |
| 2017-10-23 20:57:57 | vstinner | set | nosy: +vstinner messages: +msg304840 |
| 2017-10-23 17:34:11 | vstinner | set | pull_requests: +pull_request4061 |
| 2017-10-22 11:11:08 | pitrou | set | status: open -> closed resolution: fixed stage: patch review -> resolved |
| 2017-10-22 11:10:50 | pitrou | set | messages: +msg304742 |
| 2017-10-22 10:45:33 | pitrou | set | keywords: +patch stage: needs patch -> patch review pull_requests: +pull_request4048 |
| 2017-10-01 09:49:11 | pitrou | set | type: enhancement -> performance |
| 2017-10-01 06:11:04 | serhiy.storchaka | set | type: enhancement components: + Extension Modules, - Library (Lib) versions: - Python 3.4, Python 3.5, Python 3.6, Python 3.8 keywords: +easy (C) nosy: +serhiy.storchaka,pitrou,davin messages: +msg303449 stage: needs patch |
| 2017-10-01 01:43:01 | Daniel Colascione | create | |