2014-05-30 22:08:51 +08:00
|
|
|
// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
|
2015-01-21 21:50:02 +08:00
|
|
|
#include "test.h"
|
2012-12-04 23:46:05 +08:00
|
|
|
|
2014-10-24 17:27:34 +08:00
|
|
|
#if defined(__linux__)
|
|
|
|
#define USE_PTHREAD_SETNAME_NP __GLIBC_PREREQ(2, 12)
|
Add NetBSD support in test/tsan/thread_name*.cc
Summary:
A snipped from the documentation of thread_setname_np(3):
NAME
pthread_getname_np - get and set descriptive name of a thread
LIBRARY
POSIX Threads Library (libpthread, -lpthread)
SYNOPSIS
#include <pthread.h>
int
pthread_getname_np(pthread_t thread, char *name, size_t len);
int
pthread_setname_np(pthread_t thread, const char *name, void *arg);
Sponsored by <The NetBSD Foundation>
Reviewers: joerg, dvyukov, eugenis, vitalybuka, kcc
Reviewed By: dvyukov
Subscribers: kubamracek, llvm-commits, #sanitizers
Tags: #sanitizers
Differential Revision: https://reviews.llvm.org/D37306
llvm-svn: 312159
2017-08-31 03:40:47 +08:00
|
|
|
#define tsan_pthread_setname_np pthread_setname_np
|
2014-10-24 17:27:34 +08:00
|
|
|
#elif defined(__FreeBSD__)
|
|
|
|
#include <pthread_np.h>
|
|
|
|
#define USE_PTHREAD_SETNAME_NP 1
|
2018-02-10 22:44:12 +08:00
|
|
|
#define tsan_pthread_setname_np pthread_set_name_np
|
Add NetBSD support in test/tsan/thread_name*.cc
Summary:
A snipped from the documentation of thread_setname_np(3):
NAME
pthread_getname_np - get and set descriptive name of a thread
LIBRARY
POSIX Threads Library (libpthread, -lpthread)
SYNOPSIS
#include <pthread.h>
int
pthread_getname_np(pthread_t thread, char *name, size_t len);
int
pthread_setname_np(pthread_t thread, const char *name, void *arg);
Sponsored by <The NetBSD Foundation>
Reviewers: joerg, dvyukov, eugenis, vitalybuka, kcc
Reviewed By: dvyukov
Subscribers: kubamracek, llvm-commits, #sanitizers
Tags: #sanitizers
Differential Revision: https://reviews.llvm.org/D37306
llvm-svn: 312159
2017-08-31 03:40:47 +08:00
|
|
|
#elif defined(__NetBSD__)
|
|
|
|
#define USE_PTHREAD_SETNAME_NP 1
|
|
|
|
#define tsan_pthread_setname_np(a, b) pthread_setname_np((a), "%s", (void *)(b))
|
2014-10-24 17:27:34 +08:00
|
|
|
#else
|
|
|
|
#define USE_PTHREAD_SETNAME_NP 0
|
|
|
|
#endif
|
|
|
|
|
2012-12-04 23:46:05 +08:00
|
|
|
extern "C" void AnnotateThreadName(const char *f, int l, const char *name);
|
|
|
|
|
|
|
|
int Global;
|
|
|
|
|
|
|
|
void *Thread1(void *x) {
|
2015-01-21 21:50:02 +08:00
|
|
|
barrier_wait(&barrier);
|
2012-12-04 23:46:05 +08:00
|
|
|
AnnotateThreadName(__FILE__, __LINE__, "Thread1");
|
|
|
|
Global++;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *Thread2(void *x) {
|
2014-10-24 17:27:34 +08:00
|
|
|
#if USE_PTHREAD_SETNAME_NP
|
Add NetBSD support in test/tsan/thread_name*.cc
Summary:
A snipped from the documentation of thread_setname_np(3):
NAME
pthread_getname_np - get and set descriptive name of a thread
LIBRARY
POSIX Threads Library (libpthread, -lpthread)
SYNOPSIS
#include <pthread.h>
int
pthread_getname_np(pthread_t thread, char *name, size_t len);
int
pthread_setname_np(pthread_t thread, const char *name, void *arg);
Sponsored by <The NetBSD Foundation>
Reviewers: joerg, dvyukov, eugenis, vitalybuka, kcc
Reviewed By: dvyukov
Subscribers: kubamracek, llvm-commits, #sanitizers
Tags: #sanitizers
Differential Revision: https://reviews.llvm.org/D37306
llvm-svn: 312159
2017-08-31 03:40:47 +08:00
|
|
|
tsan_pthread_setname_np(pthread_self(), "Thread2");
|
2013-01-21 19:20:49 +08:00
|
|
|
#else
|
|
|
|
AnnotateThreadName(__FILE__, __LINE__, "Thread2");
|
|
|
|
#endif
|
2012-12-04 23:46:05 +08:00
|
|
|
Global--;
|
2015-01-21 21:50:02 +08:00
|
|
|
barrier_wait(&barrier);
|
2012-12-04 23:46:05 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main() {
|
2015-01-21 21:50:02 +08:00
|
|
|
barrier_init(&barrier, 2);
|
2012-12-04 23:46:05 +08:00
|
|
|
pthread_t t[2];
|
|
|
|
pthread_create(&t[0], NULL, Thread1, NULL);
|
|
|
|
pthread_create(&t[1], NULL, Thread2, NULL);
|
|
|
|
pthread_join(t[0], NULL);
|
|
|
|
pthread_join(t[1], NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK: WARNING: ThreadSanitizer: data race
|
2012-12-06 20:16:15 +08:00
|
|
|
// CHECK: Thread T1 'Thread1'
|
|
|
|
// CHECK: Thread T2 'Thread2'
|