SyncLock / Multithreading - Child Thread Reading The Values Of _do At The Same Time As Another Child Thread Is Reading The ValuesNov 13, 2009
I have a dictionary object (let's call it _do) I am using to cache some values for use in a multi-threaded program. I have a single controlling parent thread, with a timer function _doTimer() which can kick off child threads with a new instance of class MyThreadObject in each. My parent thread has _do as a property and with each time _doTimer() gets called, it may or may not repopulate _do depending on cacheflag settings. I pass a reference to _do to each instance of MyThreadObject and those threads at some point read the values of _do but DO NOT write to it.
What I want is to ensure that the child threads do not try and read _do whilst the parent thread is writing to it. Same thing but very slightly different -> I also don't want the parent thread to write to _do whilst the child threads are reading from it. However there is no problem with 1 child thread reading the values of _do at the same time as another child thread is reading the values - so ideally I do not want each child thread to completely lock out read access, only locking out Write access.. The code is roughly like this: