Author lechten
Recipients lechten, sbt
Date 2013-01-21.14:50:37
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1358779838.19.0.563422075024.issue16998@psf.upfronthosting.co.za>
In-reply-to
Content
> It only says that accesses are synchronized.  The problem is that you were assuming that "+=" involves a single access -- but that is not how python works.

Yes, I understand that by now (actually since your first comment).

> Where in the examples is there "non-process-safe" access?  (Note that waiting for the only process which modifies a value to terminate using join() will prevent races.)

In section "The multiprocessing.sharedctypes module" the assignments in the first example (function modify()) are unsafe.  None of them is protected by a lock as suggested in your first comment.  Strictly speaking, no lock is necessary in the example as there are no race conditions (the processes work in an alternating fashion without concurrency).

I certainly did not see that the example (for a *shared* memory data structure) is based on the implicit assumption of a single writer.  In contrast, I assumed that some "magic" should offer process-safe usage of "+=", which made me file this bug.  That assumption has turned out to be wrong.  To prevent others from being mislead in the same way I suggest to either protect those operations with locks (and comment on their effect) or to state the implicit assumption explicitly.

Maybe add the following after "Below is an example where a number of ctypes objects are modified by a child process:"
Note that assignments such n.value **= 2 are not executed atomically but involve two operations, a load followed by a store.  Each of these operations is protected by the Value's lock, which is dropped in between.  Thus, in scenarios with concurrent modifying processes you may want to explicitly acquire the Value's lock to ensure atomic execution (avoiding race conditions and lost updates), e.g.:
    with n.get_lock():
        n.value **= 2
History
Date User Action Args
2013-01-21 14:50:38lechtensetrecipients: + lechten, sbt
2013-01-21 14:50:38lechtensetmessageid: <1358779838.19.0.563422075024.issue16998@psf.upfronthosting.co.za>
2013-01-21 14:50:38lechtenlinkissue16998 messages
2013-01-21 14:50:37lechtencreate