Operating System - HP-UX
1754414 Members
2878 Online
108813 Solutions
New Discussion юеВ

pthread_create is failing in HP Unix server

 

pthread_create is failing in HP Unix server

I trying to execute the following program in the HP Unix server 11.11 but the following error message occurred.

/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
/usr/lib/dld.sl: Unresolved symbol: U_get_unwind_table (code) from /opt/langtools/lib/libpthread_tr.1

Pid 4074 received a SIGSEGV for stack growth failure.
Possible causes: insufficient memory or swap space,
or stack size exceeded maxssiz.
^CSegmentation fault (core dumped)

Source Code:

#include
#include
#include
#define NUM_THREADS 5

void *PrintHello(void *threadid)
{
long tid;
tid = (long)threadid;
printf("Hello World! It's me, thread #%ld!\n", tid);
pthread_exit(NULL);
}

int main(int argc, char *argv[])
{
pthread_t threads[NUM_THREADS];
int rc;
long t;
for(t=0;tprintf("In main: creating thread %ld\n", t);
rc = pthread_create(&threads[t], NULL, NULL, (void *)t);
if (rc){
printf("ERROR; return code from pthread_create() is %d\n", rc);
exit(-1);
}
}
pthread_exit(NULL);
}


I used the following command for compilation.

g++ -lpthread hello.cpp

Please check and provide your feedback.
4 REPLIES 4
Dennis Handly
Acclaimed Contributor

Re: pthread_create is failing in HP Unix server

>dld.sl: Unresolved symbol: U_get_unwind_table /opt/langtools/lib/libpthread_tr.1

This indicates you forgot to link with -lcl. Any reason you are linking with the tracing libpthread?

>g++ -lpthread hello.cpp

The -lpthread should go at the end, after the objects. Also, doesn't g++ have a special option to indicate threading?
Dennis Handly
Acclaimed Contributor

Re: pthread_create is failing in HP Unix server

>ME: doesn't g++ have a special option to indicate threading?

That's -pthread.
Emil Velez
Honored Contributor

Re: pthread_create is failing in HP Unix server

Probably want to write the program a little more systematically

/* this is create.c */
#include
#include
#include
#include

void fatal_error(int err_num, char *function);
void thread1_func();

/* Print "Hello World!", then "Good-bye World!" */
main()
{
pthread_t tid;
int return_val;
printf("start of program \n");
sleep(30);
/*
* Create a new thread to execute thread1_func().
*/
return_val = pthread_create(&tid, (pthread_attr_t *)NULL,
(void *(*)())thread1_func,
(void *)NULL);
if (return_val != 0)
fatal_error(return_val, "pthread_create()");
printf("doing more work\n");
sleep(30);

/*
* Wait for the thread to finish executing, then...
*/
return_val = pthread_join(tid, (void **)NULL);
if (return_val != 0)
fatal_error(return_val, "pthread_join()");

/* Say Good-bye */
printf("Good-bye World!\n");
exit(0);
}


/* Print error information, exit with -1 status. */
void
fatal_error(int err_num, char *function)
{
char *err_string;

err_string = strerror(err_num);
fprintf(stderr, "%s error: %s\n", function, err_string);
exit(-1);
}


/* Function to print "Hello World!". */
void
thread1_func()
{
printf("the thread is execuitng\n");
sleep(30);
printf("Hello World!\n");
pthread_exit((void *)NULL);
}
Laurent Menase
Honored Contributor

Re: pthread_create is failing in HP Unix server

try linking with libcl