From cf77fa8f9065e7ecca2f8b6667baca8fdd42392b Mon Sep 17 00:00:00 2001 From: Chris Hold Date: Wed, 8 Jul 2020 19:25:07 +0300 Subject: [PATCH] Lock access with += operator, targets https://github.com/chris-hld/spaudiopy/issues/13 --- spaudiopy/sdm.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/spaudiopy/sdm.py b/spaudiopy/sdm.py index e092ed9..677c6fc 100644 --- a/spaudiopy/sdm.py +++ b/spaudiopy/sdm.py @@ -34,6 +34,7 @@ cachedir = './__cache_dir' memory = Memory(cachedir) shared_array = None +lock = multiprocessing.Lock() # part of parallel pseudo_intensity: @@ -172,8 +173,9 @@ def render_stereo_sdm(sdm_p, sdm_phi, sdm_theta): def _render_bsdm_sample(i, p, phi, theta, hrirs): h_l, h_r = hrirs[hrirs.nearest(phi, theta)] # global shared_array - shared_array[i:i + len(h_l), 0] += p * h_l - shared_array[i:i + len(h_l), 1] += p * h_r + with lock: # synchronize access, operator += needs lock! + shared_array[i:i + len(h_l), 0] += p * h_l + shared_array[i:i + len(h_r), 1] += p * h_r @memory.cache