Problem with POSIX Threads

Hello! Can anyone say how to use pthread_join because it's a mistery for me.

1
2
3
4
5
6
pthread_t threads[subGAmount];
for (int i = 0; i < subGAmount; i++)
{
     pthread_create(&threads[i], NULL, run, (void *)i);
}
for (int i = 0; i < subGAmount; i++) pthread_join(threads[i], NULL);


g++ compiler says that "undefined reference to `pthread_join'". If I delete line for (int i = 0; i < subGAmount; i++) pthread_join(threads[i], NULL); then I get segmentation fault while running program. Maybe anyone can help me? Thanks in advance!
Last edited on
There are loads of examples online. You should thy a search engine first.
http://www.amparo.net/ce155/thread-ex.html
That is very strange. If the code compiles fine but you get a link error, then it seems like your library is messed up. You are linking against libpthread, right?

The segmentation fault is most likely occurring in other sections of your code (not posted) so you would need to post the remainder of your code.
Topic archived. No new replies allowed.