<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#ffffff">
On 10/06/2011 12:26, Henry Vermaak wrote:
<blockquote cite="mid:4DF1FF48.3090503@gmail.com" type="cite">On
10/06/11 02:09, Hans-Peter Diettrich wrote:
<br>
<blockquote type="cite">
<br>
What is "thread safe"?
<br>
</blockquote>
<br>
The definition is very clear here:
<br>
<br>
<a class="moz-txt-link-freetext" href="http://en.wikipedia.org/wiki/Thread_safety">http://en.wikipedia.org/wiki/Thread_safety</a>
<br>
</blockquote>
<br>
"A piece of code is <b>thread-safe</b> if it can be safely invoked
by multiple threads at the same time"<br>
<br>
Just to point out first, I am aware of the discussion this has
already sparked, and in the light of any argument of that
discussion, in my opinion this definition is correct.<br>
<br>
Yet I came to think of a case, for which I wonder, and would like to
hear opinions, if indeed the above statement is complete.<br>
My query is about the part: "at the same time"<br>
<br>
Now a piece of code could for example mix up thread local and thread
global data:<br>
- cache access to thread local data in a thread global way.
Subsequent calls from another thread may fail.<br>
- create an initialize some data, and store it thread-local, while
flagging it's existence thread global. Subsequent calls from another
thread may fail.<br>
Even if such code was using some sort of locking (mutex,
criticalsection, ...) it would fail. It would not need to be
executed from several threads "at the same time", it fails if
executed by several threads subsequently.<br>
<br>
However so far of course each of those would also fail, if called
"at the same time". So all my examples are indeed covered by the
original definition.<br>
<br>
The question is, is it prooven, or can it be prooven, that no code
can be constructed, that would "not fail if called at the same
time", but that would fail if called "subsequently"<br>
That would be code, for which *during* its execution the
application would be in a state valid to enter the code in another
thread, but *after* it's execution, this validity would no longer be
given.<br>
<br>
If such code can be constructed, then would the above statement have
to be extended to "subsequent calls of the piece of code" ?<br>
<br>
Martin<br>
</body>
</html>