On Friday, 3 Aug 2001, at 15:23:22,
Victor J. Orlikowski wrote:
> How about:
>
> int Acquire_Condition_Lock(struct Condition *c) {
> acquire(c->condlock);
> acquire(*(c->lock));
> c->thread_id = thread_id_of(current_thread);
> release(c->condlock);
> return 0;
> }
>
> Hence, we simply block trying to acquire the condlock.
> Once we have the condlock, all is well, no?
>
Hum, answer my own question. No.
While driving down for vacation, I thought of all the possible
deadlocks.
However, Acquire_Condition_Lock is the only one casuing them.
The following implmentation should cure it all.
int Acquire_Condition_Lock(struct Condition *c) {
int thrid = thread_id_of(current_thread);
if (c->thread_id == thrid) exit(1); /* Deadlock */
acquire(*(c->lock));
acquire(c->condlock);
c->thread_id = thread_id_of(current_thread);
release(c->condlock);
return 0;
}
As long as we always only maintain the state of c->thread_id while
holding c->lock, all will be fine. Furthermore, reads from
c->thread_id should be safe, as all write thereto should be serialized
in the implementation that includes the above Acquire_Condition_Lock.
Victor
--
Victor J. Orlikowski | The Wall is Down, But the Threat Remains!
==================================================================
[EMAIL PROTECTED] | [EMAIL PROTECTED] | [EMAIL PROTECTED]