По какой-то причине pthread_join
всегда вызывает действие SIGSEGV на моем компьютере, когда я запускаю Valgrind. Чтобы проверить это, я запустил следующий код с сайта https://computing.llnl.gov/tutorials/pthreads/. а>:
/* pthread.c */
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define NUM_THREADS 4
void *BusyWork(void *t)
{
int i;
long tid;
double result=0.0;
tid = (long)t;
printf("Thread %ld starting...\n",tid);
for (i=0; i<1000000; i++)
{
result = result + sin(i) * tan(i);
}
printf("Thread %ld done. Result = %e\n",tid, result);
pthread_exit((void*) t);
}
int main (int argc, char *argv[])
{
pthread_t thread[NUM_THREADS];
pthread_attr_t attr;
int rc;
long t;
void *status;
/* Initialize and set thread detached attribute */
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
for(t=0; t<NUM_THREADS; t++) {
printf("Main: creating thread %ld\n", t);
rc = pthread_create(&thread[t], &attr, BusyWork, (void *)t);
if (rc) {
printf("ERROR; return code from pthread_create() is %d\n", rc);
exit(-1);
}
}
/* Free attribute and wait for the other threads */
pthread_attr_destroy(&attr);
for(t=0; t<NUM_THREADS; t++) {
rc = pthread_join(thread[t], &status);
if (rc) {
printf("ERROR; return code from pthread_join() is %d\n", rc);
exit(-1);
}
printf("Main: completed join with thread %ld having a status of %ld\n",
t,(long)status);
}
printf("Main: program completed. Exiting.\n");
pthread_exit(NULL);
}
Бег
$ clang -g -o pthread pthread.c
$ valgrind --leak-check=full ./pthread
Выдает следующую ошибку valgrind:
==17283== Process terminating with default action of signal 11 (SIGSEGV)
==17283== Access not within mapped region at address 0x700002F3CC3E
==17283== at 0x10044437F: _pthread_find_thread (in /usr/lib/system/libsystem_pthread.dylib)
==17283== by 0x100446D52: _pthread_join_cleanup (in /usr/lib/system/libsystem_pthread.dylib)
==17283== by 0x100446C63: pthread_join (in /usr/lib/system/libsystem_pthread.dylib)
==17283== by 0x100000D52: main (pthread.c:50)
Мой компьютер — Mac OS X (El Capitan). Для clang я использую Apple LLVM версии 7.0.2 (clang-700.1.81). Для Valgrind я использую valgrind-3.11.0.
leak-check
на Mac, re: который Philippe W. имеет заявлено без репродуктора на linux мало шансов [sic] найти проблему с удаленной отладкой по почте - person   schedule 09.01.2017