-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
thread safe io_buffer #1
Comments
The only way I see is to mutex the whole buffer, i.e.
Even if you're willing to patch the Of course, an alternative would be to just use the |
ok
thank you for reply
Le mer. 18 déc. 2019 à 17:47, Benno Evers <[email protected]> a
écrit :
… The only way I see is to mutex the whole buffer, i.e.
// Reader thread
{ std::lock_guard<std::mutex> lock(io_mutex);
io_buffer.read(...);
}
// Writer thread
{ std::lock_guard<std::mutex> lock(io_mutex);
io_buffer.write(...);
}
Even if you're willing to patch the io_buffer to allow finer-grained
locking, I don't really see a good way to implement this. The problem is
the resetting of the read/write position when the buffer is completely
empty, so both threads really need to be able to change the write position.
Of course, an alternative would be to just use the linear_ringbuffer
instead, which supports that use case natively.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#1?email_source=notifications&email_token=ABMPSA52YFLOVFICOECP3X3QZJHZZA5CNFSM4J4LVNIKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEHGX7LQ#issuecomment-567115694>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABMPSA5NBKLLMSN5FYFTQYTQZJHZZANCNFSM4J4LVNIA>
.
|
I'd like to use io_buffer from a reader thread and a writer thread
How can I do it safely and efficiently?
The text was updated successfully, but these errors were encountered: