0

Okay so I'm trying to bubble sort two files in a separate threads(main thread and the secondary thread in which I created using pthread_create). My bubble sort works perfectly, I tested it several times so I didn't included here, my problem it is giving me segmentation fault during the line pthread_create.

I have a bubble sort functions which reads the file and sorts it. Works perfect. void *bubblesortCars(char *filename)

THE PROBLEM THIS IS GIVING ME SEGMENTATION FAULT

pthread_create(&one, NULL, (void*)&bubblesortCars, (char *)&("FirstHalf.txt"));
bubblesortCars("SecondHalf.txt");
pthread_join(one, NULL); 

HOWEVER, if I put it this way it will work perfectly, but I do not want to do it this way, because I want both threads to bubble sort simultaneously:

bubblesortCars("SecondHalf.txt");
pthread_create(&one, NULL, (void*)&bubblesortCars, (char *)&("FirstHalf.txt"));
pthread_join(one, NULL); 
  • 1
    Try posting a compilable example exhibiting the problem (an SSCCE - http://sscce.org/) - or at least your `bubblesortCars()` function. Even though the function works as intended when called directly, it may not work when two threads are using it simultaneously. Also - when you get segmentation faults - try debugging it (for instance with gdb). – sonicwave Nov 05 '14 at 17:52
  • Why did you cast to `void*` for 3rd argument? It must be `void*(*)(void*)` (pointer to function), not `void*`. – yohjp Nov 07 '14 at 12:54

0 Answers0