views:

155

answers:

2

Hi everyone !

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 ?

+3  A: 

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.

MaLio
That won't work in my architecture. The writers really have to finish their jobs before the synchro take place.I just want to know if a younger thread could gain priority against an older one to acquire a lock.
Roubachof
Writer (Synchro) will get priority on the ReaderWriterLockSlim, and the 'Readers' (your DataWriters) will complete before allowing access in 'Write' mode. You can have multiple concurrent 'Read' mode (your DataWriters), but only one thread exclusivly 'Write'(Synchro) mode.
MaLio
A: 

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

SwDevMan81