Problem with pthread_delay_np

I am geeting the follwoing error,thoug i included pthread.h ,

undefined reference to `pthread_delay_np'

hav any ideas.

All <pthread.h> tells the code is what functions take what parameters. To get the actual library code when compiled, you need to link with -lpthread. Certain libraries, like <stdio.h> get linked by default, but this is not normal behavior for most anything else.

My code,

#include<stdio.h>
#include<pthread.h>
#include<time.h>
#include<sched.h>
struct timespec ob={0,0};
void *f1()
{
 // struct timespec ob={0,0};
  printf("Thread 1 started\n");
  ob.tv_sec=5;
  ob.tv_nsec=5000000000;
  printf("i will be waiting\n");
  pthread_delay_np(&ob);
  return NULL;
}
void *f2()
{
  printf("Thread 2 started\n");
  printf("I am exiting\n");
  return NULL;
}
int main()
{
  pthread_t t1,t2;
  pthread_create(&t1,NULL,f1,NULL);
  pthread_create(&t2,NULL,f2,NULL);
  pthread_join(t1,NULL);
  pthread_join(t2,NULL);
}
 
 
vchanda@cg7:~/assess6$ cc -lpthread demo.c
/tmp/ccuEthUa.o: In function `f1':
demo.c:(.text+0x42): undefined reference to `pthread_delay_np'
collect2: ld returned 1 exit status

I think offhand pthread_delay_np() is AIX only?

You need to look at sleep() and/or nanosleep().

It is also available on HP-UX, VMS and Tru64 UNIX.

pthread_delay_np() originated in the D4 draft of the POSIX.1c standard. The main implementer of POSIX.1c D4 was OSF for Distributed Computing Environment (DCE).

The suffix _np denotes that the API is non-portable and cannot be relied on to be available on another platform.

Generally nanosleep() is what you want to use as a replacement.

The pthread_delay_np function exists on Tru64 UNIX, but not on HP-UX. This function will be available on a temporary basis in the Tru64 UNIX Migration Environment for HP-UX.

The pthread_delay_np function is a nonportable equivalent to the POSIX standard function nanosleep. Both accept a time interval using a standard POSIX struct timespec structure, which defines the interval in seconds and nanoseconds, and suspend the calling thread for at least as long as the specified interval. The major functional difference is that pthread_delay_np is based on a timed condition variable wait: it computes an absolute target time by adding the interval to the current system time, and waits until that target time arrives, disregarding any signals delivered to the thread. Changes to the system time will affect the actual interval waited. The nanosleep function waits for the specified interval regardless of system time changes; however, if a signal is delivered to the thread, and dismissed normally, nanosleep will return to the caller and can optionally return the remaining interval.

The Migration Environment contains Tru64 UNIX APIs, development tools, and commands and utilities to assist customers in migrating their applications from Tru64 UNIX to HP-UX.
_______________________________________________________________

apartamentos amueblados panama

Yes, that is what the Tru64 to HP-UX STK (Software Transition Kit) documentation says but is not actually true. At the time HP-UX was trying to encourage users of DCE threads and CMA threads to migrate to POSIX threads. Look at any of the older HP-UX documentation and you will find pthread_delay_np.