Click here to Skip to main content
Click here to Skip to main content
 
Add your own
alternative version
Go to top

PriorityLock - Release locks by priority

, 30 Nov 2006
A Monitor like class that releases locks by priority.
prioritylock.zip
Senthil.Concurrency.Utilities.PriorityLock.dll
PriorityLockTest.exe
prioritylock_src.zip
MonitorPerformance.vsp
PriorityLockPerformance.vsp
PriorityLockTest.psess
PriorityLock
Properties
PriorityLockTest
bin
Release
Properties
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using Senthil.Concurrency.Utilities;

class PriorityMonitorTest
{
    static PriorityLock priorityMonitor = new PriorityLock();
    static object monitor = new object();

    public static void Main()
    {
        for (int i = 0; i < 10; ++i)
        {
            new Thread(ThreadProc).Start(1);
            new Thread(ThreadProc).Start(2);
            new Thread(ThreadProc).Start(3);
        }

    }
    // This is the implementation of the threads. It simply acquires
    // the lock and then sleeps for 1 second, waking up later to release
    // the lock. It does nothing else significant.
    static void ThreadProc(object target)
    {
        int x = (int)target;
        try
        {
            //Monitor.Enter(monitor);
            priorityMonitor.Lock(x);
            Console.WriteLine(x);
            Thread.Sleep(1000);
        }
        finally
        {
            priorityMonitor.Unlock();
            //Monitor.Exit(monitor);
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

S. Senthil Kumar
Software Developer Atmel R&D India Pvt. Ltd.
India India
I'm a 27 yrs old developer working with Atmel R&D India Pvt. Ltd., Chennai. I'm currently working in C# and C++, but I've done some Java programming as well. I was a Microsoft MVP in Visual C# from 2007 to 2009.
 
You can read My Blog here. I've also done some open source software - please visit my website to know more.

| Advertise | Privacy | Mobile
Web03 | 2.8.140926.1 | Last Updated 30 Nov 2006
Article Copyright 2006 by S. Senthil Kumar
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid