Skip to content

Commit

Permalink
Lock access with += operator, targets #13
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-hld committed Jul 8, 2020
1 parent 41459f0 commit cf77fa8
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions spaudiopy/sdm.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
cachedir = './__cache_dir'
memory = Memory(cachedir)
shared_array = None
lock = multiprocessing.Lock()


# part of parallel pseudo_intensity:
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit cf77fa8

Please sign in to comment.