Problem with pthread_delay_np | Unix Linux Forums | Programming

  Go Back    


Programming Post questions about C, C++, Java, SQL, and other programming languages here.

Problem with pthread_delay_np

Programming


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 07-01-2010
vijay_manpage vijay_manpage is offline
Registered User
 
Join Date: Jun 2010
Last Activity: 6 July 2010, 11:18 PM EDT
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
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.
Sponsored Links
    #2  
Old 07-01-2010
Corona688 Corona688 is offline Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 23 September 2014, 9:50 PM EDT
Location: Saskatchewan
Posts: 19,416
Thanks: 790
Thanked 3,273 Times in 3,068 Posts
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.
Sponsored Links
    #3  
Old 07-01-2010
vijay_manpage vijay_manpage is offline
Registered User
 
Join Date: Jun 2010
Last Activity: 6 July 2010, 11:18 PM EDT
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
I did that too..,

My code,


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


Last edited by Scott; 07-01-2010 at 05:46 AM.. Reason: Code tags, please...
    #4  
Old 07-01-2010
achenle achenle is offline
Registered User
 
Join Date: Jun 2009
Last Activity: 23 September 2014, 8:08 PM EDT
Posts: 681
Thanks: 1
Thanked 93 Times in 89 Posts
I think offhand pthread_delay_np() is AIX only?

You need to look at sleep() and/or nanosleep().
Sponsored Links
    #5  
Old 07-01-2010
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
who?
 
Join Date: Dec 2003
Last Activity: 22 September 2014, 9:29 PM EDT
Location: /dev/ph
Posts: 4,809
Thanks: 63
Thanked 425 Times in 394 Posts
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.
Sponsored Links
    #6  
Old 07-06-2010
proximity4 proximity4 is offline
Registered User
 
Join Date: Jul 2010
Last Activity: 6 July 2010, 5:48 AM EDT
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
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
Sponsored Links
    #7  
Old 07-06-2010
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
who?
 
Join Date: Dec 2003
Last Activity: 22 September 2014, 9:29 PM EDT
Location: /dev/ph
Posts: 4,809
Thanks: 63
Thanked 425 Times in 394 Posts
Quote:
The pthread_delay_np function exists on Tru64 UNIX, but not on HP-UX.
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.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
DHCP problem and eth1 problem sllinux UNIX for Dummies Questions & Answers 0 10-23-2009 02:45 AM
user login problem & Files listing problem. pernasivam AIX 1 06-18-2009 09:09 AM
Loop problem with one more problem aliahsan81 Shell Programming and Scripting 3 01-07-2009 01:02 AM
problem in finding a hardware problem girish.batra Solaris 8 09-09-2008 10:10 AM
ssh script problem problem pcjandyala Shell Programming and Scripting 2 07-31-2008 03:27 PM



All times are GMT -4. The time now is 12:26 AM.