mmx_nexus
June 17th, 2008, 05:12 AM
Hi,
I’m looking out for an opinion on how to do this better..
I have a shared dictionary between two threads…one thread is continuously updating it, say the updation is more than 20 times per second(financial market data) and another thread(timer) reads from the dictionary and updates a datatable which is binded to a grid.
Since it’s shared access I know I have to lock the dictionary, issue is which lock..I cant use the for example, lock(hybridDict.SyncRoot) because the writer thread should not be blocked,as it’s critical that data which flows in should be the latest and accurate and in the next read cycle I should pick the latest updated value.
Forexample if I say in thread1:
lock(hybridDict.SyncRoot)
{
//Read Dicitonary and put the latest value into datattable
}
And in thread2:
lock(hybridDict.SyncRoot)
{
//Update the dictionary,or specifically the values.
}
I’ll be running into the issue mentioned above if I implement like above…
Now another complexity is thread2 is not actually a thread but a callback method which gets invoked regularly(so multiple writer threads) and also thread1 is a timer thread which gets invoked regularly(multiple reader threads too).
What is the efficient method to implement this algorithm???
Thanks in advance,
mmx
I’m looking out for an opinion on how to do this better..
I have a shared dictionary between two threads…one thread is continuously updating it, say the updation is more than 20 times per second(financial market data) and another thread(timer) reads from the dictionary and updates a datatable which is binded to a grid.
Since it’s shared access I know I have to lock the dictionary, issue is which lock..I cant use the for example, lock(hybridDict.SyncRoot) because the writer thread should not be blocked,as it’s critical that data which flows in should be the latest and accurate and in the next read cycle I should pick the latest updated value.
Forexample if I say in thread1:
lock(hybridDict.SyncRoot)
{
//Read Dicitonary and put the latest value into datattable
}
And in thread2:
lock(hybridDict.SyncRoot)
{
//Update the dictionary,or specifically the values.
}
I’ll be running into the issue mentioned above if I implement like above…
Now another complexity is thread2 is not actually a thread but a callback method which gets invoked regularly(so multiple writer threads) and also thread1 is a timer thread which gets invoked regularly(multiple reader threads too).
What is the efficient method to implement this algorithm???
Thanks in advance,
mmx