Single lock or separate read / write locks for I / O?

I have several threads that write and read different files.

Is it possible to use one lock {} (the same variable for all protected areas) for all disk operations? So, I do not have two streams that read and write to disk at the same time to find them?

I also heard that I could also use for streams to read and another to write, is this always the case? why?

+3
source share
4 answers

Your requirement seems somewhat confusing and changing. One comment says that "streams are written to one file," and the other "all are written to the same set of files at the same time."

:

1) . , , .

2) / - , (1), , contentin . / .

2) / . , , , - , , . , , . , .

3) (2), . (2), . (2), .

4) threadpool. , - , , , - . (2), .

5) , ?

0

, , concurrency.

, (). , , . concurrency, "-".

: http://en.wikipedia.org/wiki/Readers-writers_problem

+2

If you do not get access to the code of another thread from any thread, then one object for synchronization would be enough, but this would increase the queue of threads waiting for a resource. One synchronization object for each resource or group of resources would be the best option.

+1
source

Using just one lock can slow down your application. If a stream has been writing a file for a long time, perhaps other streams should be allowed to read other files. Could you clarify how the file access flows?

0
source

All Articles