flareback Posted April 7, 2007 Posted April 7, 2007 working on a program in C. trying to use pthread_barrier_init(). the important parts to this question that I have so far is: webStress.h pthread_barrier_t *startLine; main.c #include "webStress.h" #include <pthread.h> ... if((pthread_barrier_init(startLine, NULL, 1)) == 0){ printf("error\n"); exit(0); } thread.c #include "webStress.h" #include <pthread.h> ... pthread_barrier_wait(startLine); The point of the barrier is I will have multiple threads running and I want them to all wait to begin at once. The code I have compiles fine, no errors, no warnings and I compile with the -lpthread flag. But when I run it, it segfaults in the init portion. The following is what gdb tells me. Program received signal SIGSEGV, Segmentation fault.[switching to Thread -1208600384 (LWP 961)] 0x002dab32 in pthread_barrier_init () from /lib/i686/nosegneg/libpthread.so.0 Any ideas? I can't think of anything. I know barrier isn't implemented on certain distros but I can't understand why it would compile if it wasn't on there. I've never used barriers before and don't know if i'm implementing wrong or what. at the point when I get the seg fault, I haven't created any other threads, or called pthread_barrier_wait(). The init gets called directly after checking the command line args. This is on a linux system by the way. don't know what distro, it's a school comp and my only way to get into it is ssh (unless someone can tell me how to check using ssh). Share this post Link to post Share on other sites More sharing options...
markiemrboo Posted April 7, 2007 Posted April 7, 2007 I haven't used it either, but at a guess I would say it's because the pointer you're passing for parameter #1 (startLine) is a pointer with no allocated memory. It's pointing to a random location, and I expect the pthread functions are then writing to the memory at this random location. Try these instead: pthread_barrier_t startLine; pthread_barrier_init(&startlLine, NULL, 1); pthread_barrier_wait(&startLine); or pthread_barrier_t *startLine = NULL; startLine = (pthread_barrier_t *)malloc(1 * sizeof(pthread_barrier_t)); /* possible 'memset' here */ pthread_barrier_init(startLine, NULL, 1); pthread_barrier_wait(startLine); This is on a linux system by the way. don't know what distro, it's a school comp and my only way to get into it is ssh (unless someone can tell me how to check using ssh). `uname -a` Share this post Link to post Share on other sites More sharing options...
flareback Posted April 7, 2007 Posted April 7, 2007 thanks markiemrboo, uname -a [teamB@teamB1 jkcj]$ uname -aLinux teamB1 2.6.17-1.2157_FC5xenU #1 SMP Wed Jul 12 00:46:43 EDT 2006 i686 athlon i386 GNU/Linux is that Fedora Core 5? It is being run virtually through xen i know that much. anyways, the first worked. Didn't have to malloc anything. Share this post Link to post Share on other sites More sharing options...
markiemrboo Posted April 7, 2007 Posted April 7, 2007 thanks markiemrboo, No problem, uname -a is that Fedora Core 5? It is being run virtually through xen i know that much. Looks like it might be. Not much of a Linux guy as you all know, but FC5 seems to suggest it is anyways, the first worked. Didn't have to malloc anything. Either should work, just done in slightly different ways Share this post Link to post Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now