Beispiel #1
0
    public static void Main(string[] args)
    {
        Storage db = StorageFactory.Instance.CreateStorage();

        db.Open("testconcur.dbs");
        L2List list = (L2List) db.GetRoot();
        if (list == null)
        {
            list = new L2List();
            list.head = new L2Elem();
            list.head.next = list.head.prev = list.head;
            db.SetRoot(list);
            for (int i = 1; i < nElements; i++)
            {
                L2Elem elem = new L2Elem();
                elem.count = i;
                elem.linkAfter(list.head);
            }
        }
        TestConcur[] threads = new TestConcur[nThreads];
        for (int i = 0; i < nThreads; i++)
        {
            threads[i] = new TestConcur(db);
            threads[i].Start();
        }
        for (int i = 0; i < nThreads; i++)
        {
            threads[i].Join();
        }
        db.Close();
    }
Beispiel #2
0
    public static void Main(String[] args)
    {
        db = StorageFactory.Instance.CreateStorage();
        db.Open("testconcur.dbs");
        L2List list = (L2List)db.Root;

        if (list == null)
        {
            list           = new L2List();
            list.head      = new L2Elem();
            list.head.next = list.head.prev = list.head;
            db.Root        = list;
            for (int i = 1; i < nElements; i++)
            {
                L2Elem elem = new L2Elem();
                elem.count = i;
                elem.linkAfter(list.head);
            }
        }
        Thread[] threads = new Thread[nThreads];
        for (int i = 0; i < nThreads; i++)
        {
            threads[i] = new Thread(new ThreadStart(run));
            threads[i].Start();
        }
#if !COMPACT_NET_FRAMEWORK
        for (int i = 0; i < nThreads; i++)
        {
            threads[i].Join();
        }
        db.Close();
#endif
    }
Beispiel #3
0
    public static void run()
    {
        L2List list = (L2List)db.Root;

        for (int i = 0; i < nIterations; i++)
        {
            long sum = 0, n = 0;
            list.SharedLock();
            L2Elem head = list.head;
            L2Elem elem = head;
            do
            {
                elem.Load();
                sum += elem.count;
                n   += 1;
            } while ((elem = elem.next) != head);
            Debug.Assert(n == nElements && sum == (long)nElements * (nElements - 1) / 2);
            list.Unlock();
            list.ExclusiveLock();
            L2Elem last = list.head.prev;
            last.unlink();
            last.linkAfter(list.head);
            list.Unlock();
        }
#if COMPACT_NET_FRAMEWORK
        lock (typeof(TestConcur))
        {
            if (++nFinishedThreads == nThreads)
            {
                db.Close();
            }
        }
#endif
    }
 static void RotateList(L2List list)
 {
     using (ExclusiveLock xl = new ExclusiveLock(list)) 
     {
         L2Elem last = list.head.prev;
         last.unlink();
         last.linkAfter(list.head);
     }
 }    
 static void RotateList(L2List list)
 {
     using (ExclusiveLock xl = new ExclusiveLock(list))
     {
         L2Elem last = list.head.prev;
         last.unlink();
         last.linkAfter(list.head);
     }
 }
 static void WorkWithList(L2List list, bool rotate)
 {
     using (UpdateLock ul = new UpdateLock(list)) 
     {
         TraverseList(list);
         if (rotate)
         {
             RotateList(list);
         }
     }
 }
 static void WorkWithList(L2List list, bool rotate)
 {
     using (UpdateLock ul = new UpdateLock(list))
     {
         TraverseList(list);
         if (rotate)
         {
             RotateList(list);
         }
     }
 }
 static void TraverseList(L2List list)
 {
     using (SharedLock sl = new SharedLock(list)) 
     {
         L2Elem head = list.head;             
         L2Elem elem = head;
         long sum = 0, n = 0;
         do { 
             elem.Load();
             sum += elem.count;
             n += 1;
         } while ((elem = elem.next) != head);
         Debug.Assert(n == nElements && sum == (long)nElements*(nElements-1)/2);
     }
 }
 static void TraverseList(L2List list)
 {
     using (SharedLock sl = new SharedLock(list))
     {
         L2Elem head = list.head;
         L2Elem elem = head;
         long   sum = 0, n = 0;
         do
         {
             elem.Load();
             sum += elem.count;
             n   += 1;
         } while ((elem = elem.next) != head);
         Debug.Assert(n == nElements && sum == (long)nElements * (nElements - 1) / 2);
     }
 }
    static void Run()
    {
        L2List list = (L2List)db.Root;

        for (int i = 0; i < nIterations; i++)
        {
            WorkWithList(list, (i & 1) == 0);
        }
#if COMPACT_NET_FRAMEWORK
        lock (typeof(TestConcur))
        {
            if (++nFinishedThreads == nThreads)
            {
                db.Close();
            }
        }
#endif
    }
Beispiel #11
0
        public void Run(TestConfig config)
        {
            int count = config.Count;
            var res = new TestConcurResult();
            config.Result = res;

            TestConcur.nElements = count;
            var start = DateTime.Now;

            db = config.GetDatabase();
            L2List list = (L2List)db.Root;
            Tests.Assert(list == null);
            list = new L2List();
            list.head = new L2Elem();
            list.head.next = list.head.prev = list.head;
            db.Root = list;
            for (int i = 1; i < nElements; i++)
            {
                L2Elem elem = new L2Elem();
                elem.count = i;
                elem.linkAfter(list.head);
            }
            res.InsertTime = DateTime.Now - start;

            start = DateTime.Now;
            Thread[] threads = new Thread[nThreads];
            for (int i = 0; i < nThreads; i++)
            {
                threads[i] = new Thread(new ThreadStart(run));
                threads[i].Start();
            }
            #if !CF
            for (int i = 0; i < nThreads; i++)
            {
                threads[i].Join();
            }
            #endif
            db.Close();
            res.AccessTime = DateTime.Now - start;
        }
    public static void Main(String[] args) {
        db = StorageFactory.Instance.CreateStorage();
        if (args.Length > 0) 
        { 
            db.SetProperty("perst.object.cache.kind", args[0]);
        }
	    db.Open("testconcur.dbs");
        L2List list = (L2List)db.Root;
        if (list == null) { 
            list = new L2List();
            list.head = new L2Elem();
            list.head.next = list.head.prev = list.head;
            db.Root = list;
            for (int i = 1; i < nElements; i++) { 
                L2Elem elem = new L2Elem();
                elem.count = i;
                elem.linkAfter(list.head); 
            }
        }
        Thread[] threads = new Thread[nThreads];
        for (int i = 0; i < nThreads; i++) { 
            threads[i] = new Thread(new ThreadStart(Run));
            threads[i].Start();
        }
#if !COMPACT_NET_FRAMEWORK
        for (int i = 0; i < nThreads; i++) 
        { 
            threads[i].Join();
        }
        db.Close();
#endif
    }