On 4/13/22 16:51, Kevin Wolf wrote:
So the idea is that we can do bdrv_graph_co_rdlock() in one thread and
the corresponding bdrv_graph_co_rdunlock() in a different thread?

Would the unlock somehow remember the original thread, or do you use the
"sum is correct" argument and allow negative counter values, so you can
end up having count +1 in A and -1 in B to represent "no active
readers"? If this happens, it's likely to happen many times, so do we
have to take integer overflows into account then?

The counter cannot be negative, so you can use uint32_t and sum modulo 2^32. You might have a thread with counter 2^31+1 which is negative in twos complement; and a thread with counter -2^31-1 which is positive in twos complement; but their sum cancels out correctly.

Paolo

Reply via email to