On May 13, 11:48 pm, Daniel Pitts
<newsgroup.spamfil...@virtualinfinity.net> wrote:
Philipp wrote:
Hello,
I've come accross a threading problem for which I can't find a nice
solution. (SSCCP at end of post)
I have a bidimensionalarrayofobjects(view it as a 2D lattice). I
want to make atomic operations on random square 2x2 regions of the
lattice. Thus I want to lock the 4objectsof the region, then perform
the change, then unlock thoseobjects. Several threads should be
allowed to work on thearrayat the same time, if each thread is
accessing a 2x2 region which does not overlap with that of another,
they should be capable of doing the work in a parallel way.
How should I design the code to achieve this?
I was thinking about this a little longer, and one might be able to
create an algorithm that takes a Region and blocks as long as any
previously added Region is in use. I'm working on a prototype right
now, I'll post when I've completed it.
I don't know if this what you meant, but a possible approach would be
a non-blocking algorithm.
1. Take a snapshot of the objects in the region.
2. Do the work on them
3. Check if the region has not been modified.
4. Atomically commit the change if the region is the same as before in
1.
This might be particularly interesting if contention is not expected
(few threads, big array, small region) because we can limit
synchronization to point 4. Is this a way to follow?
Phil
data structure. That Lock Request would block as long as the current
structure. Once work is complete, that Lock Request can be removed from
that data-structure, unblocking other threads waiting for that region.