Skip to content

Commit

Permalink
Add proper memory fences.
Browse files Browse the repository at this point in the history
  • Loading branch information
ymmt2005 committed Nov 15, 2013
1 parent 57cf0fc commit b8d8291
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/worker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,8 @@ void worker::run() {
// recv returns EAGAIN, or some error happens.
if( m_buffer.size() > 0 )
pending.append(m_buffer.data(), m_buffer.size());

std::atomic_thread_fence(std::memory_order_release);
m_socket->release();
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/worker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class worker final: public cybozu::thread_base<worker> {
}

void wait() {
std::atomic_thread_fence(std::memory_order_release);
m_running = false;
std::uint64_t i;
ssize_t n = ::read(m_event, &i, sizeof(i));
Expand Down Expand Up @@ -76,7 +77,6 @@ class worker final: public cybozu::thread_base<worker> {
std::vector<cybozu::tcp_socket*> m_slaves;

void notify() {
std::atomic_thread_fence(std::memory_order_release);
std::uint64_t i = 1;
ssize_t n = ::write(m_event, &i, sizeof(i));
if( n == -1 )
Expand Down

0 comments on commit b8d8291

Please sign in to comment.