1. Written by readers
Written by: Write Data
Reader: Just read the data, there is no data to take away
Relationship between writer and writer: mutual exclusion
Relationship between reader and reader: no relationship
Relationship between writer and reader: synchronization, mutual exclusion
Workaround:
1) Readers first: readers are reading, the writer cannot terminate the reader until the reader is finished, the writer can write
2) Writing is preferred: The writer is writing, the reader cannot terminate the writer, until the writer finishes writing, the reader can write
2. Producer Consumers
Producer: Generating Data
Consumer: Take away data
Producer and producer: mutually exclusive relationship
Consumers and consumers: mutually exclusive relationships
Producer and Consumer: mutual exclusion, synchronous relationship
The primary role of the producer is to generate a certain amount of data into the buffer, and then repeat the process. At the same time, consumers consume the data in buffers. The key to this issue is to ensure that producers do not add data when the buffer is full, and consumers do not consume data when the buffer is empty.
To solve this problem, you must let the producer hibernate when the buffer is full, until the next time the consumer consumes the data in the buffer, the producer can be awakened and begin adding data to the buffer. Similarly, you can let consumers hibernate when the buffer is empty, wait until the producer adds data to the buffer, and then wake the consumer.
3. Difference
1) The data has been there, there is no vacancy to write, there is data to read the problem, the writer can overwrite the previous value, the reader will not consume data, the data will not disappear.
2) allows multiple readers concurrent access, while the consumer is mutually exclusive, write not only with the writer is mutually exclusive, but also with the reader also mutually exclusive, for the producer/consumer only with self-exclusion.
This article is from the "lovemeright" blog, make sure to keep this source http://lovemeright.blog.51cto.com/10808587/1827955
Reader and writer, producer and consumer