On Mon, Nov 26, 2001, Oleg Goldshmidt wrote about "Re: threads question":
> > What is this last return statement?? Returning from main? That's not
> > something you're supposed to do in a multithreaded program. It
> > might, for example, free the entire malloc pool, including arg which
> > is later freed in the second thread, causing a segmentation fault.
> 
> You are right that there should not be a return statement, but it is
> not what is happening: free() is OK, according to the

Sorry for the false alarm (you should return() from main like that, but
this is not the problem here).
The real problem in your code is that you passed a NULL as the first parameter
to pthread_create! It should be somewhere that pthread_create can store
the id of the resulting thread... (see pthread_create(3)).

Replacing         if (pthread_create(NULL, NULL, start, arg) != 0)
by
        pthread_t tid;
        if (pthread_create(&tid, NULL, start, arg) != 0)

Should fix it.


-- 
Nadav Har'El                        |      Monday, Nov 26 2001, 12 Kislev 5762
[EMAIL PROTECTED]             |-----------------------------------------
Phone: +972-53-245868, ICQ 13349191 |"Do you want to restart Windows now or
http://nadav.harel.org.il           |wait for the next crash?"

=================================================================
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]

Reply via email to