static int getktid()
{
+#ifdef __NR_gettid
return syscall(__NR_gettid);
+#else
+ return -1;
+#endif
}
static int getvgtid()
return res;
}
-static void SignalHandler(const int iSignal)
+static void print_thread_id(const char* const label)
{
if (s_debug)
{
char msg[256];
- snprintf(msg, sizeof(msg), "Signal %d was delivered to kernel thread ID %d"
- " / Valgrind thread ID %d\n",
- iSignal, getktid(), getvgtid());
+ snprintf(msg, sizeof(msg),
+ "%spid %d / kernel thread ID %d / Valgrind thread ID %d\n",
+ label, getpid(), getktid(), getvgtid());
write(STDOUT_FILENO, msg, strlen(msg));
}
}
-void* thread_func(void* thread_arg)
+static void SignalHandler(const int iSignal)
{
- struct timespec tsRemain, tsDelay;
+ print_thread_id("Signal was delivered to ");
+}
- if (s_debug)
- {
- printf("thread: kernel thread ID %d / Valgrind thread ID %d\n",
- getktid(), getvgtid());
- }
+void* thread_func(void* thread_arg)
+{
+ print_thread_id("thread: ");
- tsDelay.tv_sec = 10;
- tsDelay.tv_nsec = 0;
- clock_nanosleep(CLOCK_MONOTONIC, 0, &tsDelay, &tsRemain);
+ sleep(10);
//assert(result < 0 && errno == EINTR);
return 0;
vgthreadid = getvgtid();
- if (s_debug)
- {
- printf("main: kernel thread ID %d / Valgrind thread ID %d\n",
- getktid(), vgthreadid);
- }
+ print_thread_id("main: ");
{
struct sigaction sa;
// Wait until the thread is inside clock_nanosleep().
tsDelay.tv_sec = 0;
tsDelay.tv_nsec = 20 * 1000 * 1000;
- clock_nanosleep(CLOCK_MONOTONIC, 0, &tsDelay, 0);
+ nanosleep(&tsDelay, 0);
// And send SIGALRM to the thread.
pthread_kill(threadid, SIGALRM);
pthread_join(threadid, 0);