This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: problems with pthreads
doesn't the 'main' thread exit before the other 2 threads are really
started?
m.
On 18 Feb 2003 12:13:15 +0000
Christian Schaefer <caefer@krachstoff.net> wrote:
>hi there,
>
>the following code compiles just fine, but when run it just stops with
>no error message. used gcc 3.2.1 with -lpthread option.
>
>regards
>/christian
>
>debugger (Anjuta) tells me:
>---------------------------------------------------------------------
>Running program ...
>Reading symbols from /lib/libc.so.6...done
>Reading symbols from /lib/ld-linux.so.2...done
>[Switching to Thread 16384 (LWP 4708)]
>main (argc=1, argv=0xbffffa04) at main.c:15 (<--this line is red!)
>[New Thread 32769 (LWP 4709)]
>[New Thread 32769 (LWP 4710)]
>[New Thread 32769 (LWP 4711)]
>
>source
>---------------------------------------------------------------------
>#define NUM_THREADS 5
>void print_message_function( void *ptr )
>{
> char *message;
> message = (char *) ptr;
> printf("%s ", message);
>}
>
>int main(int argc, char *argv[])
>{
> pthread_t thread1, thread2;
> char *message1 = "Hello";
> char *message2 = "World";
>
> pthread_create( &thread1, NULL,
> (void*)&print_message_function, (void*) message1);
> pthread_create(&thread2, NULL,
> (void*)&print_message_function, (void*) message2);
> return 0;
>}
>
>