Roubachof
Roubachof

Reputation: 3401

Increase thread priority on wait handles

I am running a application with a LOT of thread. All these threads are updating database with GPS coordinates. Meanwhile, the application can receive a synchronization request. Before the server can process this request, all the writing threads have to finish their job. Therefore I am using an array of wait handles to manage this.

So here is the scenario:

The actors:

1 Synchro Thread
N Writing Thread

N Writing threads are working. One Synchro thread arrives at the wait handles stop. It claims for the lock. Doing so, it is put at the end of the list of "claiming lock threads".

Problem is: this list could be very long, or my synchro thread is top priority.

How could I achieve to give it a VIP pass ?

Upvotes: 0

Views: 591

Answers (2)

SwDevMan81
SwDevMan81

Reputation: 49978

Sounds like you need to implement a priority locking system. There is an example here

Upvotes: 0

MaLio
MaLio

Reputation: 2530

Sounds like you should be using a System.Threading.ReaderWriterLockSlim instead. The writers can act in 'Read' mode of the lock, the Synchro thread requireing exclusive access can enter 'Write' mode.

Upvotes: 2

Related Questions