locked
Threading - Lock Priority RRS feed

  • Question

  • Hi, here's my scenario:

    My server app runs:
    1)  an update thread that write on objects..
    N) client threads tipically used to retrieve informations, but somethimes they can do some writes

    Updater is triggered by a windows form timer once every T seconds, but when it's triggered he need to be faster as possible and all other threads must give priority to him, so his lock request should skip the queue.
    I think that raising the priority of the updater thread will only grant it extra time and no priority over the locking queue.. it is right?
    If yes how i can solve the problem?
    Since i'm not the creator of the timer class rising the timer thread priprity must be done during
    the implementation for the event handler?
    At last I noticed the presence in the framework of System.Timers namespace
    according to MSDN System.Timer is better for multithreaded application like mine, but i think i'm missing the big difference.

    Monday, May 21, 2007 8:31 PM

Answers

  • You can set the relative priority of a thread; but with a Windows Forms Timer the thread is the main thread.
    Monday, May 21, 2007 8:46 PM
  • I used Windows.Form.Timer since it was the fastest thing to implement for an initial stage, now i'm doing some serious evaluations for a better timer... maybe the Threading timer is the most appropriate..

    Monday, May 21, 2007 9:13 PM
  • In the book CLR via C# ,Jeffery Richter described the 3 Timers in detail.

    System.Threading.Timer uses a thread getting form ThreadPool.
    System.Windows.Forms.Timer works with WM_TIMER message.
    System.Timers.Timer may be seen as a encapsulation of System.Threading.Timer
    Jeffery Richter suggested us NOT to use System.Timers.Timer cause it possiblly be remove form FCL.

    System.Threading.Timer is very reliable, should be choosed firstly.
    Tuesday, May 22, 2007 9:23 AM
  •  Alx_it wrote:
    ok, during my next iteration i'll change Form.Timer for with a Threading.Timer, but the problem with the priority is still unsolved.


    What is the need for such priority that one thread should trump others? It seems like, as I am reading it, this process seems to be a two way data flow.

    If your main thread needs to trump the other's data, then possibly using a broadcast methodology such as a ReaderWriterLock where the main thread is the writer and writes the info, and before the worker thread(s) write the actual data, they check the RWL data for trump values.

    Also, you may want to check out an article in CodeProject PriorityLock which implemented may allow you to do what is needed.
    Tuesday, May 22, 2007 2:50 PM

All replies

  • You can set the relative priority of a thread; but with a Windows Forms Timer the thread is the main thread.
    Monday, May 21, 2007 8:46 PM
  • The problem with using Windows.Forms.Timer is that it will only occur if the GUI thread isn't busy doing something.

     

    Maybe you can explain why you're using Windows.Forms.Timer rather than Threading.Timer or System.Timer?

    Monday, May 21, 2007 8:48 PM
  • I used Windows.Form.Timer since it was the fastest thing to implement for an initial stage, now i'm doing some serious evaluations for a better timer... maybe the Threading timer is the most appropriate..

    Monday, May 21, 2007 9:13 PM
  • In the book CLR via C# ,Jeffery Richter described the 3 Timers in detail.

    System.Threading.Timer uses a thread getting form ThreadPool.
    System.Windows.Forms.Timer works with WM_TIMER message.
    System.Timers.Timer may be seen as a encapsulation of System.Threading.Timer
    Jeffery Richter suggested us NOT to use System.Timers.Timer cause it possiblly be remove form FCL.

    System.Threading.Timer is very reliable, should be choosed firstly.
    Tuesday, May 22, 2007 9:23 AM
  • ok, during my next iteration i'll change Form.Timer for with a Threading.Timer, but the problem with the priority is still unsolved.
    Tuesday, May 22, 2007 12:03 PM
  •  Alx_it wrote:
    ok, during my next iteration i'll change Form.Timer for with a Threading.Timer, but the problem with the priority is still unsolved.


    What is the need for such priority that one thread should trump others? It seems like, as I am reading it, this process seems to be a two way data flow.

    If your main thread needs to trump the other's data, then possibly using a broadcast methodology such as a ReaderWriterLock where the main thread is the writer and writes the info, and before the worker thread(s) write the actual data, they check the RWL data for trump values.

    Also, you may want to check out an article in CodeProject PriorityLock which implemented may allow you to do what is needed.
    Tuesday, May 22, 2007 2:50 PM
  • I already noticed the PriorityLock article, but i think that also a ReaderWriterLock should work thanks
    Wednesday, May 23, 2007 9:40 AM