Skip to content

Commit 9c8b9cb

Browse files
committed
Final version including:
1. All past blocking points are resolved. 2. Atomicity, + Implementation and rebuild Semlock are atomic (protected via the dedicated semaphore), + Release, get_value and is_zero methods are atomic too (protected via the mutex of each semaphore), + Acquire function is nearly-atomic. 3. Shared memory, + The shared memory and its associated semphore have unique names based on the main process ID. + a new counter was added to count pending thread when blocking acquire operations happen. + When a Semlock is destroyed, the shared memory and its dediocted semaphore are destroyed too if there is no more opened Semclock.
1 parent b446eff commit 9c8b9cb

13 files changed

Lines changed: 640 additions & 849 deletions

File tree

Lib/multiprocessing/spawn.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,12 @@ def get_preparation_data(name):
201201
main_path = os.path.join(process.ORIGINAL_DIR, main_path)
202202
d['init_main_from_path'] = os.path.normpath(main_path)
203203

204+
# see gh-125828: workaround on MacOS to emulate `get_value` on Semaphore.
205+
if sys.platform == 'darwin':
206+
import _multiprocessing
207+
d['_macosx_sharedmem_name'] = _multiprocessing._MACOSX_SHAREDMEM_NAME
208+
d['_macosx_shmlock_name'] = _multiprocessing._MACOSX_SHMLOCK_NAME
209+
204210
return d
205211

206212
#
@@ -245,6 +251,18 @@ def prepare(data):
245251
elif 'init_main_from_path' in data:
246252
_fixup_main_from_path(data['init_main_from_path'])
247253

254+
# see gh-125828: workaround on MacOS to emulate `get_value` on Semaphore.
255+
if sys.platform == 'darwin' and '_macosx_sharedmem_name' in data:
256+
import _multiprocessing
257+
_multiprocessing._set_shm_names(
258+
data['_macosx_sharedmem_name'],
259+
data['_macosx_shmlock_name']
260+
)
261+
# Update module attributes so grandchild processes also get
262+
# the correct names when get_preparation_data() is called.
263+
_multiprocessing._MACOSX_SHAREDMEM_NAME = data['_macosx_sharedmem_name']
264+
_multiprocessing._MACOSX_SHMLOCK_NAME = data['_macosx_shmlock_name']
265+
248266
# Multiprocessing module helpers to fix up the main module in
249267
# spawned subprocesses
250268
def _fixup_main_from_name(mod_name):
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Fix the not implemented ``get_value`` for :class:`multiprocessing.Semaphore` on MacOSX
2-
by adding a dedicated workaround in ``_multiprocessing.SemLock``.
3-
All changes are located in the ``semaphore.c`` file of `multiprocessing` module.
4-
1+
Fix the not implemented ``get_value`` for :class:`multiprocessing.Semaphore` on MacOSX
2+
by adding a dedicated workaround in ``_multiprocessing.SemLock``.
3+
All changes are located in the ``semaphore.c`` file of `multiprocessing` module.
4+

Modules/_multiprocessing/clinic/semaphore.c.h

Lines changed: 33 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/_multiprocessing/dump_shm_macosx/dump_shared_mem.c

Lines changed: 0 additions & 102 deletions
This file was deleted.

Modules/_multiprocessing/dump_shm_macosx/make_all.sh

Lines changed: 0 additions & 2 deletions
This file was deleted.

Modules/_multiprocessing/dump_shm_macosx/readme.md

Lines changed: 0 additions & 41 deletions
This file was deleted.

Modules/_multiprocessing/dump_shm_macosx/reset_shared_mem.c

Lines changed: 0 additions & 81 deletions
This file was deleted.

0 commit comments

Comments
 (0)