Home > pthread create bus > pthread_create bus error

Pthread_create Bus Error

here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up pthread bus error up vote 2 down vote favorite I'm doing an exercise. The goal is to make a program in C to crack DES encrypted password. Right now I have the following flow of execution: Load dictionary. Dictionary search. Brute force search of the first 4 characters. Dictionary search combined with brute force (searching for combinations). Only dictionary words of 7-6 characters. Brute force search of the first 5 characters. Dictionary search combined with brute force (searching for combinations). Only dictionary words of 5-4 characters. Brute force search of up to 8 characters. The program works fine, but I want to improve it by using multiple threads: 1st thread - main 2nd thread - dictionary and dictionary combined with brute force search 3rd thread - brute force search I've started by making a basic dictionary search thread function, but it fails with Bus Error (Mac OS X) where it should start reading words from the dictionary file. Same code works fine in the regular non- thread function... Here is the code: #include #include #include #include #define _XOPEN_SOURCE #define MAXLINE 40 #define MAXPASS 9 /* dictionary search thread function */ void * dictionary(void * argv) { /* initializing SALT */ char salt[3]; // defining salt (length is always 2 chars + "\0") strncpy(salt, argv, 2); // copying the first 2 characters from encrypted password to salt salt[2] = '\0'; // placing null character to make salt a string /* defining and initializing password */ char password[14]; strcpy(password, argv); /* defining candidate */ char candidate[MAXPASS]; /* opening file */ FILE *fp; if ((fp = fopen("/usr/share/dict/words", "r")) == NULL) { printf("Error: Can not open file.\n"); return (v

here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Bus error on OSX - http://stackoverflow.com/questions/8551267/pthread-bus-error pthreads up vote 2 down vote favorite am trying to get my head around the following: Have a small program am trying to port to OSX(intel) which calls function doWork() via pthread_create, in the function, I start by creating an array of long like such: long myarray[DIMENSION] on OSX, for the following values of DIMENSION, I get the following: 0->65434 = fine 65435->67037 = SIGBUS http://stackoverflow.com/questions/3329379/bus-error-on-osx-pthreads 67037+ = SIGSEGV I'm totally confused here, I understand that SIGBUS is due to memory alignment issues usually, I checked sizeof(long) and it appears to be 8 on this platform. Can somebody point me in the right direction of docs I should be reading here? Here is the source: #include pthread.h #include stdio.h #define NUM_THREADS 5 #define DIMENSION 12345 void *doStuff(void *threadid) { long array[DIMENSION]; pthread_exit(NULL); } int main (int argc, char *argv[]) { pthread_t threads[NUM_THREADS]; int rc; long t; for(t=0; t lt NUM_THREADS; t++){ printf("In main: creating thread %ld\n", t); rc = pthread_create(&threads[t], NULL, doStuff, (void *)t); if (rc){ printf("ERROR; return code from pthread_create() is %d\n", rc); exit(-1); } } pthread_exit(NULL); } c osx pthreads share|improve this question asked Jul 25 '10 at 13:40 lochii 515 add a comment| 1 Answer 1 active oldest votes up vote 6 down vote accepted It would appear you're overflowing the stack. You'll need to either turn the long array into a malloced one, or use pthread_attr_setstacksize and friends to create a larger stack when you call pthread_create. Default thread stack sizes vary a lot before platforms, which would explain why the code works on other platforms. https://computing.llnl.gov/tutorials/p

Jun Sun Date: Thu, 19 Oct 2000 15:31:54 -0700 Sender: owner-linux-mips@oss.sgi.com I am running a simple pthread_create() test. The thread gets created, but the creating thread gets BUS error after https://www.linux-mips.org/archives/linux-mips/2000-10/msg00191.html the function call. In fact, it gets SIGUSR1 signal. Does anybody know what is wrong here? It looks to me that creating thread is waiting for the created thread to start up, but somehow did not install the signal handler correctly!? I am running with the "stable" toolchain that I generated recently, i.e., pthread_create bus binutil 2.8.1, egcs 1.0.3a and glibc2.0.6. I attached the program and the strace output. Thanks. Jun#include #include #include typedef void * (*pthread_func_t) (void *); void myfunc(void *arg) { printf("slave : myfunc runs.\n"); } main() { int ret; pthread_t thread; printf("master : before create a thread ... \n"); ret = pthread_create(&thread, NULL, pthread_create bus error (pthread_func_t)myfunc, NULL); perror("after creating a thread ... :"); printf("master : after create a thread ... %d(%s)\n", ret, strerror(ret)); if (ret == EAGAIN) { printf("error is EAGAIN\n"); } } execve("./pthread", ["./pthread"], [/* 15 vars */]) = 0 brk(0) = 0x10010fb0 cacheflush(0x7ffffbb8, 0x28, 0x3) = 0 cacheflush(0x7ffffb40, 0x28, 0x3) = 0 mmap(ptrace: umoven: Input/output error ptrace: umoven: Input/output error ) = 715829248 open("/etc/ld.so.preload", O_RDONLY) = -1 ENOENT (No such file or directory) cacheflush(0x7ffffaa8, 0x28, 0x3) = 0 open("/etc/ld.so.cache", O_RDONLY) = -1 ENOENT (No such file or directory) open("/lib/libpthread.so.0", O_RDONLY) = 3 mmap(ptrace: umoven: Input/output error ptrace: umoven: Input/output error ) = 715833344 munmap(0x2aaac000, 4096) = 0 mmap(ptrace: umoven: Input/output error ptrace: umoven: Input/output error ) = 715833344 mprotect(0x2aab7000, 281200, PROT_NONE) = 0 mmap(NULL, 0, PROT_NONE, MAP_FILE, 0, 0) = 0x2aaf6000 close(3) = 0 open("/lib/libc.so.6", O_RDONLY) = 3 mmap(ptrace: umoven: Input/output error ptrace: umoven: Input/output error ) = 716161024 munmap(0x2aafc000, 4096) = 0 mmap(ptrace: umoven: Input/output error ptrace: umoven: Input/output error )

 

Related content

No related pages.