Synchronization for multiple readers, single recording?

Another synchronization issue ... I hope you guys are not annoyed;)

Suppose the following scenario: one central data structure (very large, so I really do not want to make it unchanged and copy it whenever a change occurs. I do not even want to store several copies in memory) several reader threads that access this a read-only data structure and one write stream that keeps the data structure up to date in the background.

I am currently synchronizing all calls to a data structure that works just fine (no synchronization effects, no deadlocks). What I don't like about this approach is that most of the time I have a lot of active reader streams, and the stream of letters is only active from time to time. Now, it is completely unnecessary for reader threads to wait for other reader threads to complete. They can easily access the data structure in parallel until the recording stream is currently being recorded.

Is there a beautiful and elegant way to solve this kind of scenario?

EDIT: Thanks so much for the answers and links! Let me add another short and related question: if the code executed in the critical sections of the reader takes a very short time (for example, just searching in a hash table), is it even worth considering introducing one of the methods that you describe, or is the serialization effect of the locks not so bad in this case? Scalability and performance are very important. What do you think?

EDIT 2: I just looked at one implementation of a single script for reading / disassembling - locking, and this implementation uses a monitor to synchronize some code in the WaitToRead method. Doesn't this lead to the same serialization effect that I wanted to avoid in the first place? (However, considering that the synchronized code is short and fast)

+5
7

RTL (sysutils) : TMultiReadExclusiveWriteSynchroniser

. , . "BeginRead" "BeginWrite" . "EndRead" "EndWrite".

+9

, ( , vartec), Reader (s) -Writer-Lock.

+5
+3

Reader-Writer . , , .

, , , . , , : . , .

+2

, , ( ), , , , .

+1

, - , , .

, , , , -, starvation , . , . , , . , :

ReaderWriterLock . , AcquireReaderLock , Monitor Enter.

.NET, , .

+1

- - , . Tutorial , , - Delphi. , , D2009 .

0

All Articles