[Zope-dev] Threads and locks

Itamar Shtull-Trauring itamars@ibm.net
Thu, 27 Apr 2000 10:49:53 +0300


Michel Pelletier wrote:

> If another thread commits this same opeation before this thread does,
> the usual conflit rules apply.  The commit will get a ConflictError, and
> this request will start over and get a whole new copy of the objects
> from the database complete with the newer values.  I'm not even sure if
> locks are necessary at all, this code is threadsafe and as you pointed
> out each thread gets its own copy of the object, the transacitonal
> nature of change the objects should keep your data consistent at all
> times.

Can I absolutely trust that if I have a counter with value of 30, and I add
5 to it in two different threads at once I'll always end up as 40?

In most cases it won't be terrible if one of the transactions aborted in the
end because of the ConflictError, but I'm dealing with Other People's Money
here.  In fact, Money That Other People Owe Us, which could be considered
even more important :).
 
-- 
Itamar S.T.  itamars@ibm.net