is Python fully object oriented ?
ssthapa at harper.uchicago.edu
ssthapa at harper.uchicago.edu
Tue Jan 16 17:52:06 EST 2001
Martijn Faassen <m.faassen at vet.uu.nl> wrote:
>Delaney, Timothy <tdelaney at avaya.com> wrote:
>[snip me describing how object attributes can be copied into local
> variables]
>> Ooh - dangerous in a multithreaded app ... ;)
>
>I have little experience programming multithreaded apps, but find it
>hard to believe that avoiding this techniques makes all the danger go
>away without the need for special attention anyway. Could you elaborate?
Your code read and made a copy of an instance variable, did stuff
with it and then updated it. The problem is that without adding a mutex
to serialize reads and writes to the variable you could have a case where the
same instance has the method called twice by different threads. E.g
thread 1: thread 2:
calls method ...
copies instance var calls method
... copies instance var
does stuff with var does stuff with var
updates instance var ...
exits method updates var
... exits method
The end result in this case is that thread 1's update of the instance variable
gets overwritten by thread 2. This can happen in other permutations with the
net result that the code may work fine, or it may break and this breakage can
depend on the timing of the threads causing you to go insane while debugging
the program. :( The typical solution is to prevent any other threads from
reading or writing the variable while the method is running using a mutex.
--
------------------------------------------------------------------
|
Suchandra Thapa | "There are only two kinds of math books.
s-thapaNO at SPAMuchicago.edu | Those you cannot read beyond the first
| sentence, and those you cannot read
| beyond the first page."
| -C.N. Yang
------------------------------------------------------------------
More information about the Python-list
mailing list