R
R
Roman Sarvarov2022-03-08 23:40:03
go
Roman Sarvarov, 2022-03-08 23:40:03

When to use RWMutex instead of Mutex?

Hello!
I can not master RWMutex.
Can you give an example of a situation when you need to use RWMutex, and not a regular mutex?
You can even give the code of a super simple example, when a simple Mutex does not solve the problem.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
WinPooh32, 2022-03-09
@megakor

In the case of an ordinary mutex, only exclusive access to the resource is possible, i.e. only one thread has read or write access.
And when we have RWMutex, then the number of threads when reading is unlimited, but when accessing for writing, access again becomes exclusive for only one thread.
RWMutex is used to increase throughput when the resource is accessed more frequently for reading than for writing.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question