URI: 
       tlibthread: abort on single-threaded lock contention - plan9port - [fork] Plan 9 from user space
  HTML git clone git://src.adamsgaard.dk/plan9port
   DIR Log
   DIR Files
   DIR Refs
   DIR README
   DIR LICENSE
       ---
   DIR commit faf1fb6c7e14e95e54865b660db7501ed390ea9e
   DIR parent f35a04866f298aa4b0fa6846da0c0187751ce9b2
  HTML Author: Russ Cox <rsc@swtch.com>
       Date:   Wed,  9 Jul 2008 11:41:14 -0400
       
       libthread: abort on single-threaded lock contention
       
       Diffstat:
         M src/libthread/thread.c              |      24 ++++++++++++++++++++++++
       
       1 file changed, 24 insertions(+), 0 deletions(-)
       ---
   DIR diff --git a/src/libthread/thread.c b/src/libthread/thread.c
       t@@ -463,6 +463,12 @@ needstack(int n)
                }
        }
        
       +static int
       +singlethreaded(void)
       +{
       +        return threadnproc == 1 && _threadprocs->nthread == 1;
       +}
       +
        /*
         * locking
         */
       t@@ -481,6 +487,12 @@ threadqlock(QLock *l, int block, ulong pc)
                        unlock(&l->l);
                        return 0;
                }
       +
       +        if(singlethreaded()){
       +                fprint(2, "qlock deadlock\n");
       +                abort();
       +        }
       +
        /*print("qsleep %p @%#x by %p\n", l, pc, (*threadnow)()); */
                addthread(&l->waiting, (*threadnow)());
                unlock(&l->l);
       t@@ -537,6 +549,10 @@ threadrlock(RWLock *l, int block, ulong pc)
                        unlock(&l->l);
                        return 0;
                }
       +        if(singlethreaded()){
       +                fprint(2, "rlock deadlock\n");
       +                abort();
       +        }
                addthread(&l->rwaiting, (*threadnow)());
                unlock(&l->l);
                _threadswitch();
       t@@ -558,6 +574,10 @@ threadwlock(RWLock *l, int block, ulong pc)
                        unlock(&l->l);
                        return 0;
                }
       +        if(singlethreaded()){
       +                fprint(2, "wlock deadlock\n");
       +                abort();
       +        }
                addthread(&l->wwaiting, (*threadnow)());
                unlock(&l->l);
                _threadswitch();
       t@@ -613,6 +633,10 @@ threadwunlock(RWLock *l, ulong pc)
        static void
        threadrsleep(Rendez *r, ulong pc)
        {
       +        if(singlethreaded()){
       +                fprint(2, "rsleep deadlock\n");
       +                abort();
       +        }
                addthread(&r->waiting, proc()->thread);
                qunlock(r->l);
                _threadswitch();