1 //===-- sanitizer_stoptheworld_testlib.cc ---------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
9 // Dynamic library to test StopTheWorld functionality.
10 // When loaded with LD_PRELOAD, it will periodically suspend all threads.
11 //===----------------------------------------------------------------------===//
13 clang++ -fno-exceptions -g -fPIC -I. \
14 sanitizer_common/tests/sanitizer_stoptheworld_testlib.cc \
15 sanitizer_common/sanitizer_*.cc -shared -lpthread -o teststoptheworld.so
16 LD_PRELOAD=`pwd`/teststoptheworld.so /your/app
19 #include "sanitizer_common/sanitizer_platform.h"
28 #include "sanitizer_common/sanitizer_stoptheworld.h"
31 const uptr kSuspendDuration
= 3;
32 const uptr kRunDuration
= 3;
34 void Callback(const SuspendedThreadsList
&suspended_threads_list
,
36 sleep(kSuspendDuration
);
39 void *SuspenderThread(void *argument
) {
42 StopTheWorld(Callback
, NULL
);
47 __attribute__((constructor
)) void StopTheWorldTestLibConstructor(void) {
49 pthread_create(&thread_id
, NULL
, SuspenderThread
, NULL
);
53 #endif // SANITIZER_LINUX