Because of multithreading semantics, this is not reliable.
Sergei Organov
osv at javad.com
Thu May 4 08:50:11 EDT 2006
"Olaf Meding" <OlafMeding at noSpam.compuserve.com> writes:
>> return result before that line, some other thread added a value !
>
> Sure, but that is the nature of using threads and a mutex. I hope you are
> you not saying that every function that uses a mutex should have a comment
> saying this is not "reliable"?
Strictly speaking, mutex has nothing to do about it, -- if there were no
mutex there the problem would have been even worse, so this is the
nature of accessing shared resources by multiple threads.
Somewhat similar example is accessing a file after checking for its
existence in a multi-tasking OS:
if fileExists(fileName):
openFile(fileName)
has the same problem, -- at open_file time one can't rely on existence
of the file, so the check for existence is useless.
--
Sergei.
More information about the Python-list
mailing list