Skip to content

Commit

Permalink
Reduce intermittent test failures in CI by fixing bugs found by asan …
Browse files Browse the repository at this point in the history
…and tsan (#926)

* Fix intermittent crashes in TestContinuationsWithTask.

The one now marked 7 was creating a task that wrote to a stack variable,
but never joined with that stack variable. This would cause random
crashes whenever that stack position got clobbered.

* Fix several errors found by thread sanitizer.

* Fix more data races :/

* Fix data races in the asio server found by tsan.

* Avoid VS2015 warning C4800.
  • Loading branch information
BillyONeal authored Oct 18, 2018
1 parent 14b439c commit 3a140eb
Show file tree
Hide file tree
Showing 10 changed files with 421 additions and 390 deletions.
12 changes: 7 additions & 5 deletions Release/include/cpprest/astreambuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
****/
#pragma once

#include <math.h>
#include <atomic>
#include <cstring>
#include <ios>
#include <memory>
#include <cstring>
#include <math.h>

#include "pplx/pplxtasks.h"
#include "cpprest/details/basic_types.h"
Expand Down Expand Up @@ -745,7 +746,10 @@ namespace streams

std::exception_ptr m_currentException;
// The in/out mode for the buffer
bool m_stream_can_read, m_stream_can_write, m_stream_read_eof, m_alloced;
std::atomic<bool> m_stream_can_read;
std::atomic<bool> m_stream_can_write;
std::atomic<bool> m_stream_read_eof;
std::atomic<bool> m_alloced;


private:
Expand Down Expand Up @@ -1208,5 +1212,3 @@ namespace streams
};

}}


13 changes: 7 additions & 6 deletions Release/include/pplx/pplxlinux.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
#include <boost/thread/mutex.hpp>
#include <boost/thread/condition_variable.hpp>
#else
#include <mutex>
#include <mutex>
#include <atomic>
#include <condition_variable>
#endif

Expand Down Expand Up @@ -80,7 +81,7 @@ namespace platform
static const unsigned int timeout_infinite = 0xFFFFFFFF;

event_impl()
: _signaled(false)
: _signaled(false)
{
}

Expand Down Expand Up @@ -209,7 +210,7 @@ namespace platform
_M_cs.lock();
_M_owner = id;
_M_recursionCount = 1;
}
}
}

void unlock()
Expand All @@ -223,12 +224,12 @@ namespace platform
{
_M_owner = -1;
_M_cs.unlock();
}
}
}

private:
cpprest_synchronization::mutex _M_cs;
volatile long _M_owner;
std::atomic<long> _M_owner;
long _M_recursionCount;
};

Expand Down Expand Up @@ -298,7 +299,7 @@ namespace extensibility
#else
typedef details::linux_scheduler default_scheduler_t;
#endif

namespace details
{
/// <summary>
Expand Down
Loading

0 comments on commit 3a140eb

Please sign in to comment.