diff options
author | Pavel Labath <labath@google.com> | 2016-05-10 07:54:25 +0000 |
---|---|---|
committer | Pavel Labath <labath@google.com> | 2016-05-10 07:54:25 +0000 |
commit | ebc7135f8e529470c9745e8324d74f48f0fc3749 (patch) | |
tree | cf18e8340883179ea63f0dbd0361bd058cbab5b9 /lldb/packages/Python/lldbsuite | |
parent | bdb54eb4573f554854531cfebde54f102b618d68 (diff) | |
download | bcm5719-llvm-ebc7135f8e529470c9745e8324d74f48f0fc3749.tar.gz bcm5719-llvm-ebc7135f8e529470c9745e8324d74f48f0fc3749.zip |
Fix race in TestExitDuringStep and unify pseudo_barrier handling
Summary:
TestExitDuringStep was very rarely hanging on the buildbots. I can't be sure, but I believe this
was because of the fact that it declared its pseudo_barrier variable as "volatile int", which is
not sufficient to guarantee corectness (also, all other tests used atomic variables for this, and
they were passing reliably AFAIK). Besides switching to an atomic variable in this test as well,
I have also took this opportunity to unify all the copies of the pseudo_barrier code to a single
place to reduce the chance of this happening again.
Reviewers: clayborg
Subscribers: lldb-commits
Differential Revision: http://reviews.llvm.org/D20065
llvm-svn: 269025
Diffstat (limited to 'lldb/packages/Python/lldbsuite')
9 files changed, 36 insertions, 105 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/thread/break_after_join/main.cpp b/lldb/packages/Python/lldbsuite/test/functionalities/thread/break_after_join/main.cpp index a63079524ee..f9f33fda82b 100644 --- a/lldb/packages/Python/lldbsuite/test/functionalities/thread/break_after_join/main.cpp +++ b/lldb/packages/Python/lldbsuite/test/functionalities/thread/break_after_join/main.cpp @@ -19,24 +19,12 @@ volatile int g_test = 0; -// Note that although hogging the CPU while waiting for a variable to change -// would be terrible in production code, it's great for testing since it -// avoids a lot of messy context switching to get multiple threads synchronized. -#define do_nothing() - -#define pseudo_barrier_wait(bar) \ - --bar; \ - while (bar > 0) \ - do_nothing(); - -#define pseudo_barrier_init(bar, count) (bar = count) - // A barrier to synchronize all the threads. -std::atomic_int g_barrier1; +pseudo_barrier_t g_barrier1; // A barrier to keep the threads from exiting until after the breakpoint has // been passed. -std::atomic_int g_barrier2; +pseudo_barrier_t g_barrier2; void * break_thread_func () diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/thread/concurrent_events/main.cpp b/lldb/packages/Python/lldbsuite/test/functionalities/thread/concurrent_events/main.cpp index ac2535cd2bf..10b55bff3ba 100644 --- a/lldb/packages/Python/lldbsuite/test/functionalities/thread/concurrent_events/main.cpp +++ b/lldb/packages/Python/lldbsuite/test/functionalities/thread/concurrent_events/main.cpp @@ -23,22 +23,10 @@ using namespace std; #include <sys/types.h> #include <unistd.h> -// Note that although hogging the CPU while waiting for a variable to change -// would be terrible in production code, it's great for testing since it -// avoids a lot of messy context switching to get multiple threads synchronized. -#define do_nothing() - -#define pseudo_barrier_wait(bar) \ - --bar; \ - while (bar > 0) \ - do_nothing(); - -#define pseudo_barrier_init(bar, count) (bar = count) - typedef std::vector<std::pair<unsigned, void*(*)(void*)> > action_counts; typedef std::vector<pthread_t> thread_vector; -std::atomic_int g_barrier; +pseudo_barrier_t g_barrier; int g_breakpoint = 0; int g_sigusr1_count = 0; std::atomic_int g_watchme; diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/thread/create_during_step/main.cpp b/lldb/packages/Python/lldbsuite/test/functionalities/thread/create_during_step/main.cpp index 3a00248c022..70681fd1160 100644 --- a/lldb/packages/Python/lldbsuite/test/functionalities/thread/create_during_step/main.cpp +++ b/lldb/packages/Python/lldbsuite/test/functionalities/thread/create_during_step/main.cpp @@ -13,19 +13,9 @@ #include <atomic> #include <thread> -// Note that although hogging the CPU while waiting for a variable to change -// would be terrible in production code, it's great for testing since it -// avoids a lot of messy context switching to get multiple threads synchronized. #define do_nothing() -#define pseudo_barrier_wait(bar) \ - --bar; \ - while (bar > 0) \ - do_nothing(); - -#define pseudo_barrier_init(bar, count) (bar = count) - -std::atomic_int g_barrier; +pseudo_barrier_t g_barrier; volatile int g_thread_created = 0; volatile int g_test = 0; diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/thread/exit_during_break/main.cpp b/lldb/packages/Python/lldbsuite/test/functionalities/thread/exit_during_break/main.cpp index 3570637207d..a032da835ea 100644 --- a/lldb/packages/Python/lldbsuite/test/functionalities/thread/exit_during_break/main.cpp +++ b/lldb/packages/Python/lldbsuite/test/functionalities/thread/exit_during_break/main.cpp @@ -19,27 +19,15 @@ volatile int g_test = 0; -// Note that although hogging the CPU while waiting for a variable to change -// would be terrible in production code, it's great for testing since it -// avoids a lot of messy context switching to get multiple threads synchronized. -#define do_nothing() - -#define pseudo_barrier_wait(bar) \ - --bar; \ - while (bar > 0) \ - do_nothing(); - -#define pseudo_barrier_init(bar, count) (bar = count) - // A barrier to synchronize all the threads except the one that will exit. -std::atomic_int g_barrier1; +pseudo_barrier_t g_barrier1; // A barrier to synchronize all the threads including the one that will exit. -std::atomic_int g_barrier2; +pseudo_barrier_t g_barrier2; // A barrier to keep the first group of threads from exiting until after the // breakpoint has been passed. -std::atomic_int g_barrier3; +pseudo_barrier_t g_barrier3; void * break_thread_func () diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/thread/exit_during_step/main.cpp b/lldb/packages/Python/lldbsuite/test/functionalities/thread/exit_during_step/main.cpp index d1b364b8baa..45adf28ce81 100644 --- a/lldb/packages/Python/lldbsuite/test/functionalities/thread/exit_during_step/main.cpp +++ b/lldb/packages/Python/lldbsuite/test/functionalities/thread/exit_during_step/main.cpp @@ -12,20 +12,10 @@ #include <thread> -// Note that although hogging the CPU while waiting for a variable to change -// would be terrible in production code, it's great for testing since it -// avoids a lot of messy context switching to get multiple threads synchronized. #define do_nothing() -#define pseudo_barrier_wait(bar) \ - --bar; \ - while (bar > 0) \ - do_nothing(); - -#define pseudo_barrier_init(bar, count) (bar = count) - // A barrier to synchronize thread start. -volatile int g_barrier; +pseudo_barrier_t g_barrier; volatile int g_thread_exited = 0; diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/thread/multi_break/main.cpp b/lldb/packages/Python/lldbsuite/test/functionalities/thread/multi_break/main.cpp index 01f4b8f98ea..c3d695dbc74 100644 --- a/lldb/packages/Python/lldbsuite/test/functionalities/thread/multi_break/main.cpp +++ b/lldb/packages/Python/lldbsuite/test/functionalities/thread/multi_break/main.cpp @@ -15,19 +15,7 @@ #include <atomic> #include <thread> -// Note that although hogging the CPU while waiting for a variable to change -// would be terrible in production code, it's great for testing since it -// avoids a lot of messy context switching to get multiple threads synchronized. -#define do_nothing() - -#define pseudo_barrier_wait(bar) \ - --bar; \ - while (bar > 0) \ - do_nothing(); - -#define pseudo_barrier_init(bar, count) (bar = count) - -std::atomic_int g_barrier; +pseudo_barrier_t g_barrier; volatile int g_test = 0; diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/thread/step_out/main.cpp b/lldb/packages/Python/lldbsuite/test/functionalities/thread/step_out/main.cpp index b4c6216d6bf..31f9a1576b9 100644 --- a/lldb/packages/Python/lldbsuite/test/functionalities/thread/step_out/main.cpp +++ b/lldb/packages/Python/lldbsuite/test/functionalities/thread/step_out/main.cpp @@ -13,19 +13,7 @@ #include <atomic> #include <thread> -// Note that although hogging the CPU while waiting for a variable to change -// would be terrible in production code, it's great for testing since it -// avoids a lot of messy context switching to get multiple threads synchronized. -#define do_nothing() - -#define pseudo_barrier_wait(bar) \ - --bar; \ - while (bar > 0) \ - do_nothing(); - -#define pseudo_barrier_init(bar, count) (bar = count) - -std::atomic_int g_barrier; +pseudo_barrier_t g_barrier; volatile int g_test = 0; diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/thread/thread_exit/main.cpp b/lldb/packages/Python/lldbsuite/test/functionalities/thread/thread_exit/main.cpp index e498db7895d..c57db9f4852 100644 --- a/lldb/packages/Python/lldbsuite/test/functionalities/thread/thread_exit/main.cpp +++ b/lldb/packages/Python/lldbsuite/test/functionalities/thread/thread_exit/main.cpp @@ -12,21 +12,9 @@ #include <atomic> #include <thread> -// Note that although hogging the CPU while waiting for a variable to change -// would be terrible in production code, it's great for testing since it -// avoids a lot of messy context switching to get multiple threads synchronized. -#define do_nothing() - -#define pseudo_barrier_wait(bar) \ - --bar; \ - while (bar > 0) \ - do_nothing(); - -#define pseudo_barrier_init(bar, count) (bar = count) - -std::atomic_int g_barrier1; -std::atomic_int g_barrier2; -std::atomic_int g_barrier3; +pseudo_barrier_t g_barrier1; +pseudo_barrier_t g_barrier2; +pseudo_barrier_t g_barrier3; void * thread1 () diff --git a/lldb/packages/Python/lldbsuite/test/make/test_common.h b/lldb/packages/Python/lldbsuite/test/make/test_common.h index a1ed364574e..a002f9fa9a4 100644 --- a/lldb/packages/Python/lldbsuite/test/make/test_common.h +++ b/lldb/packages/Python/lldbsuite/test/make/test_common.h @@ -42,3 +42,26 @@ #define lldb_enable_attach() #endif + +#ifdef __cplusplus +#include <atomic> + +// Note that although hogging the CPU while waiting for a variable to change +// would be terrible in production code, it's great for testing since it +// avoids a lot of messy context switching to get multiple threads synchronized. + +typedef std::atomic<int> pseudo_barrier_t; +#define pseudo_barrier_wait(barrier) \ + do \ + { \ + --(barrier); \ + while ((barrier).load() > 0) \ + ; \ + } while (0) + +#define pseudo_barrier_init(barrier, count) \ + do \ + { \ + (barrier) = (count); \ + } while (0) +#endif // __cplusplus |