"""
DeadlockTest.py

The purpose of this programme is to experiment with
deadlock detection in Stackless Python

February 18th, 2009

<song>Plug in Baby - Muse </song>
"""

import stackless
from   DeadlockDetector  import DeadlockDetector

global detector

def T(name, receiving, sending):
    detector.registerResources(stackless.getcurrent(), [receiving, sending])
    receiving.receive()
    sending.send()
    print "done"

if __name__  == "__main__":

   detector = DeadlockDetector()

   c1 = stackless.channel()
   c2 = stackless.channel()
   c3 = stackless.channel()
   channels = [c1, c2, c3]

   stackless.tasklet(T)("T1",c1,c3)
   stackless.tasklet(T)("T2",c2,c1)
   stackless.tasklet(T)("T3",c3,c2)

   stackless.run()

   detector.detect()
   detector.__dumpGraph__()
   detector.__dumpHoldings__()
