简体   繁体   中英

Segmentation fault in function that reads file and with threads

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 *?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM