Timeline for ReadWriteSerializer
Current License: CC BY-SA 3.0
10 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Apr 11, 2018 at 3:16 | vote | accept | Shukant Pal | ||
| Mar 19, 2018 at 20:21 | comment | added | G. Sliepen |
My suggested version of enterAsWriter() keeps the spinlock locked if onlineReaders becomes zero, because it then breaks before calling SpinUnlock(). But again, that's not the best way to go; you'll have writer starvation as a problem, and you will keep the spinlock locked for an extended amount of time when you have writers.
|
|
| Mar 19, 2018 at 20:18 | comment | added | G. Sliepen |
Atomic instructions, such as with a LOCK prefix, may or may not be efficient. It depends on your CPU architecture, cache coherency, access patterns, cacheline sharing and so on. Even if it is more efficient, then the question is whether the compiler and or the CPU will preserve the order between spinlock operations and atomic operations on onlineReaders. I'd first get it to work using only your spinlocks, and look at further optimizations later.
|
|
| Mar 19, 2018 at 10:36 | comment | added | Blasco | @SukantKumar post your updated code in a different question if you want would like to receive more reviews. If it's for reference, post it as an answer | |
| Mar 19, 2018 at 2:41 | comment | added | Shukant Pal | Should I post my updated code, too? | |
| Mar 19, 2018 at 2:39 | comment | added | Shukant Pal |
Also, your code doesn't certain that a reader coming after the writer will be denied, right? Because, enterAsWriter() will leave the lock in the loop, meanwhile the reader could pick it up and start reading, right?
|
|
| Mar 19, 2018 at 2:38 | comment | added | Shukant Pal |
Nice answer; but on the other hand - I've built atomic primitives too that use inline assembly to use the LOCK prefix. Is Atomic::dec(&onlineReaders); also efficient?
|
|
| S Mar 19, 2018 at 2:14 | history | suggested | Tolani | CC BY-SA 3.0 |
fixed grammar
|
| Mar 19, 2018 at 0:53 | review | Suggested edits | |||
| S Mar 19, 2018 at 2:14 | |||||
| Mar 18, 2018 at 14:34 | history | answered | G. Sliepen | CC BY-SA 3.0 |