Skip to content
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

Client thread safety #679

Closed
miketsts opened this issue Oct 4, 2020 · 1 comment
Closed

Client thread safety #679

miketsts opened this issue Oct 4, 2020 · 1 comment

Comments

@miketsts
Copy link
Contributor

miketsts commented Oct 4, 2020

Hi, @yhirose

Issue #492 states that the client is not thread safe.
Just few days later, you have implemented commit e022b8b which wraps ClientImpl::send() with two (!) mutex guards - request_mutex_ and socket_mutex_. Can we consider now that the thread safety has been provided?
I really want to send now requests to my server in asynchronous way. My alternative is to create a second client object for the second sending thread.

Thanks a lot!

@yhirose
Copy link
Owner

yhirose commented Oct 4, 2020

@miketsts, since ClientImpl::send() is now protected with request_mutext_, yes, it can be considered as thread safe. But the down side is that the second send() call will be blocked until the first call exits from std::lock_guard<std::recursive_mutex> request_mutex_guard(request_mutex_)... But it's guaranteed that the second request will reuse the same socket if the keep-alive condition is still met. If 'simultaneous' or concurrent requests are necessary, we still have to make another client objects. Hope this explanation helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants