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

FIx multi thread calls asyncWrite concurrently. #74

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

g-xianhui
Copy link

Multiple thread may excute asyncWrite at the same time.
1. Thread A request quite a lot RedisAsyncClient::command, all the
command post to RedisClientImpl::strand.
2. Thread B execute commands in strand one by one. The first asyncWrite
swap dataWrited and dataQueued, so other doAsyncCommand won't enter
asyncWrite.
3. the first asyncWrite call ends with a boost::asio::async_write, and
left a later asyncWrite as handler.
4. boost::asio::async_write complete, thread C excute the handler
asyncWrite, clear dataWrited.
5. Now thread B execute doAsyncCommand, and find dataWrited was empty,
so it enters asyncWrite concurrently!

1. Thread A request quite a lot RedisAsyncClient::command, all the
command post to RedisClientImpl::strand.
2. Thread B execute commands in strand one by one. The first asyncWrite
swap dataWrited and dataQueued, so other doAsyncCommand won't enter
asyncWrite.
3. the first asyncWrite call ends with a boost::asio::async_write, and
left a later asyncWrite as handler.
4. boost::asio::async_write complete, thread C excute the handler
asyncWrite, clear dataWrited.
5. Now thread B execute doAsyncCommand, and find dataWrited was empty,
so it enters asyncWrite concurrently!
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

Successfully merging this pull request may close these issues.

None yet

1 participant