libthread: abort on single-threaded lock contention
This commit is contained in:
parent
f35a04866f
commit
faf1fb6c7e
1 changed files with 24 additions and 0 deletions
|
|
@ -463,6 +463,12 @@ needstack(int n)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
singlethreaded(void)
|
||||||
|
{
|
||||||
|
return threadnproc == 1 && _threadprocs->nthread == 1;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* locking
|
* locking
|
||||||
*/
|
*/
|
||||||
|
|
@ -481,6 +487,12 @@ threadqlock(QLock *l, int block, ulong pc)
|
||||||
unlock(&l->l);
|
unlock(&l->l);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(singlethreaded()){
|
||||||
|
fprint(2, "qlock deadlock\n");
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
|
||||||
/*print("qsleep %p @%#x by %p\n", l, pc, (*threadnow)()); */
|
/*print("qsleep %p @%#x by %p\n", l, pc, (*threadnow)()); */
|
||||||
addthread(&l->waiting, (*threadnow)());
|
addthread(&l->waiting, (*threadnow)());
|
||||||
unlock(&l->l);
|
unlock(&l->l);
|
||||||
|
|
@ -537,6 +549,10 @@ threadrlock(RWLock *l, int block, ulong pc)
|
||||||
unlock(&l->l);
|
unlock(&l->l);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
if(singlethreaded()){
|
||||||
|
fprint(2, "rlock deadlock\n");
|
||||||
|
abort();
|
||||||
|
}
|
||||||
addthread(&l->rwaiting, (*threadnow)());
|
addthread(&l->rwaiting, (*threadnow)());
|
||||||
unlock(&l->l);
|
unlock(&l->l);
|
||||||
_threadswitch();
|
_threadswitch();
|
||||||
|
|
@ -558,6 +574,10 @@ threadwlock(RWLock *l, int block, ulong pc)
|
||||||
unlock(&l->l);
|
unlock(&l->l);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
if(singlethreaded()){
|
||||||
|
fprint(2, "wlock deadlock\n");
|
||||||
|
abort();
|
||||||
|
}
|
||||||
addthread(&l->wwaiting, (*threadnow)());
|
addthread(&l->wwaiting, (*threadnow)());
|
||||||
unlock(&l->l);
|
unlock(&l->l);
|
||||||
_threadswitch();
|
_threadswitch();
|
||||||
|
|
@ -613,6 +633,10 @@ threadwunlock(RWLock *l, ulong pc)
|
||||||
static void
|
static void
|
||||||
threadrsleep(Rendez *r, ulong pc)
|
threadrsleep(Rendez *r, ulong pc)
|
||||||
{
|
{
|
||||||
|
if(singlethreaded()){
|
||||||
|
fprint(2, "rsleep deadlock\n");
|
||||||
|
abort();
|
||||||
|
}
|
||||||
addthread(&r->waiting, proc()->thread);
|
addthread(&r->waiting, proc()->thread);
|
||||||
qunlock(r->l);
|
qunlock(r->l);
|
||||||
_threadswitch();
|
_threadswitch();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue