Re: Threads and statics
Stefan Ram wrote:
Daniele Futtorovic writes:
That's a tautology. But there *are* cases where you need exclusive
access to more than one resource at the same time.
Inventing freely without knowledge, I would first try to pack
such resources into a single ??meta resource??, which then can
be obtained or released by a single atomic action, again.
The very fact that multi-threaded programs exists proves one
can avoid deadlocks in such cases -- no need to look any
further.
Then, the existence of erroneous programs would prove what?
For the meaning of the verb ??prove?? in software engineering,
see for example this report:
http://machineslikeus.com/news/building-safety-nets-critical-systems
.
The book /Java Concurrency in Practice/ (informally, JCIP) by Goetz, et al.,
shed light on these issues for me.
If there is a well-defined order of acquisition for multiple locks, you can
avoid deadlock. Trouble arises when acquirers act in different sequence,
e.g., one grabs A then B, whilst another grabs B then A.
One lock for multiple resources is another pattern in the book. It goes into
detail on how to reason about such scenarios.
--
Lew
Honi soit qui mal y pense.
http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg