On Mon, Nov 26, 2001, Oleg Goldshmidt wrote about "threads question":
> static void* start(void* arg)
> {
>       int c = *((int*)arg);
>       free(arg);
>       .....
> }
> 
> int main(void)
> {
>       int* arg = NULL;
> 
>       if ((arg = (int*)malloc(sizeof(*arg))) == NULL)
>...
>       if (pthread_create(NULL, NULL, start, arg) != 0)
>       {
>               free(arg);
>               fprintf(stderr,"Error: %s\n",strerror(errno));
>               return EXIT_FAILURE;
>       }
> 
>       return EXIT_SUCCESS;
> }
> 

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.
To reiterate - any thread might simply 'return', but the main thread may
not.

Try replacing "return EXIT_SUCCESS" by "pause()" (for example) and see
if it now works.

-- 
Nadav Har'El                        |      Monday, Nov 26 2001, 12 Kislev 5762
[EMAIL PROTECTED]             |-----------------------------------------
Phone: +972-53-245868, ICQ 13349191 |I before E except after C. We live in a
http://nadav.harel.org.il           |weird society!

=================================================================
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