UNIX Socket FAQ

A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

#1 2009-02-10 10:51 AM

vishy_85
Member
Registered: 2009-02-10
Posts: 3

Re: threading problem

#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>

void *print_message_function( void *ptr );

main()
{
     pthread_t thread1, thread2;
     char *message1 = "Thread 1";
     char *message2 = "Thread 2";
     int  iret1, iret2;

    /* Create independent threads each of which will execute function */

     iret1 = pthread_create( &thread1, NULL, print_message_function, (void*) message1);
     iret2 = pthread_create( &thread2, NULL, print_message_function, (void*) message2);

     /* Wait till threads are complete before main continues. Unless we  */
     /* wait we run the risk of executing an exit which will terminate   */
     /* the process and all threads before the threads have completed.   */

     pthread_join( thread1, NULL);
     pthread_join( thread2, NULL); 

     printf("Thread 1 returns: %d\n",iret1);
     printf("Thread 2 returns: %d\n",iret2);
     exit(0);
}

void *print_message_function( void *ptr )
{
     char *message;
     message = (char *) ptr;
     printf("%s \n", message);
}

im new to the threading concept.the code im trying to execute above, it shows no errors on compiling . but the program goes into an infinite loop when executed. any idea as to where im wrong
??? running the code on HP-UX 11.11

/usr/lib/dld.sl: Unresolved symbol: U_get_unwind_table (code)  from /opt/langtools/lib/libpthread_tr.1
/usr/lib/dld.sl: Unresolved symbol: U_get_unwind_table (code)  from /opt/langtools/lib/libpthread_tr.1
/usr/lib/dld.sl: Unresolved symbol: U_get_unwind_table (code)  from /opt/langtools/lib/libpthread_tr.1
Pid 2998 received a SIGSEGV for stack growth failure.
Possible causes: insufficient memory or swap space,
or stack size exceeded maxssiz. 
Segmentation fault (core dumped)

Offline

#2 2009-02-10 01:59 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,761
Website

Re: threading problem

Odd...  It works just fine for me on Linux...

There are some compiler warnings (are you compiling with warnings enabled?):
you never return a value from print_message_function(), even though it's declared
to return a void* pointer, and you fail to declare a proper int return value for main(),
letting it be inferred K&R style...  But, nothing serious...  I certainly see no way it can
possibly result in an infinite loop... *shrug*

Offline

#3 2009-02-11 03:42 AM

i3839
Oddministrator
From: Amsterdam
Registered: 2003-06-07
Posts: 2,200

Re: threading problem

No idea what /usr/lib/dld.sl is, but  guess it's compiled against a different
libpthread library than which is installed, or something along that line.

Offline

#4 2009-02-11 05:53 AM

vishy_85
Member
Registered: 2009-02-10
Posts: 3

Re: threading problem

thanks a lot rob , i did not specify the thread as joinable and the return value value for main , fixed it . it works now :)

Offline

#5 2009-02-11 08:36 AM

Nope
Administrator
From: Germany
Registered: 2004-01-24
Posts: 384
Website

Re: threading problem

It's a HP-UX problem. It uses other default settings for the most common things, including sockets and threads. Basically all programs I've seen that run on Linux and HP-UX have a lot preprocessor code to deal with that problem.

So vishy_85, you can't use Linux code or most other free examples in the web without checking the needed settings first.

Offline

Board footer

Powered by FluxBB