Property Write Lock

In my class, I have this property:

public List<MyObject> mCollection { get; set; }

This collection is used in some different streams.

What would I like to do to allow writing of this property only when all threads have finished reading mCollection.

Something like receiving and issuing a token and allowing recording only when all tokens are issued. Is there something similar in the framework?

Thanks in advance

+4
source share
2 answers

There are many ways to achieve this. To keep it simple, make your readers interact by synchronizing with each other.

  • ReaderWriterLockSlim. .
  • a CountdownEvent. .
  • SignalAndWait a Barrier, , .

, .

+1

, SemaphoreSlim, , . ImmutableList .

, . , - , , IDisposable, ( , IEnumerator). , , .

, TPL Dataflow. , , , - , .

0

All Articles