Esempio n. 1
0
        public void UnlockWriteTest()
        {
            MyLM        target   = new MyLM();
            Transaction context  = new Transaction();
            Transaction context2 = new Transaction();
            Lockable    resource = new RID(RID.Type.CAR, "test");

            target.LockForWrite(context, resource);
            target.UnlockWrite(context, resource);
            target.LockForWrite(context2, resource);
        }
Esempio n. 2
0
        public void LockConversionTest4()
        {
            MyLM target = new MyLM();

            target.setDeadlockTimeout(1000);
            Transaction context  = new Transaction();
            Transaction context2 = new Transaction();
            Transaction context3 = new Transaction();
            Lockable    resource = new RID(RID.Type.CAR, "test");

            target.LockForUpdate(context, resource);
            target.LockForRead(context2, resource);
            ManualResetEvent e  = new ManualResetEvent(false);
            ManualResetEvent e1 = new ManualResetEvent(false);

            ThreadPool.QueueUserWorkItem((obj) =>
            {
                target.LockForWrite(context3, resource);
                e1.Set();
            });

            ThreadPool.QueueUserWorkItem((obj) =>
            {
                target.LockForWrite(context, resource);
                Thread.Sleep(200);
                target.UnlockWrite(context, resource);
                e.Set();
            });
            target.UnlockRead(context2, resource);

            if (!e.WaitOne(3000))
            {
                Assert.Fail("Failed");
            }
            if (!e1.WaitOne(3000))
            {
                Assert.Fail("Failed");
            }
        }