SyncLock on SyncRoot

I created a synchronized queue and use SyncLock in the SyncRoot property of this queue when calling Enqueue / Dequeue methods. Methods are called from instances of standard producer / consumer classes.

Is this the correct use of the SyncRoot property?

Would it be better to create a private shared object in each class and block it?

Please explain your arguments.

+3
source share
1 answer

Yes, it is this property SyncRoot. In particular, this means that if another “wrapper” collection is created, it will probably use the same one SyncRoot, so everyone can synchronize correctly.

, , , , . - , ? ?

, , Enqueue/Dequeue. , , , .

+5

Source: https://habr.com/ru/post/1712462/


All Articles