Reputation: 63
I am having a problem writing a function that will be passed to a pthread_create. The function takes two arguments. I am getting segmentation fault while calling it.
And pthread_create:
pthread_create(&tid_array[i], NULL, searchForWord(argv[i + 2], word), &wData[i]);
Can function passed to pthread_create take other arguments than void *?
Upvotes: 0
Views: 31
Reputation: 41271
pthread_create takes a start routine, in the form of a function pointer.
The expression searchForWord(argv[i + 2], word)
is not a function pointer; it calls searchForWord in the current thread, which always returns NULL, and then passes NULL to pthread_create.
The thread start function must take a pointer-to-void parameter, but you are free to create a struct, pass a pointer to that struct into the function. You'll get a pointer-to-void, which you can cast to pointer-to-your-struct.
Upvotes: 2