l i n u x - u s e r s - g r o u p - o f - d a v i s
L U G O D
 
Next Meeting:
November 4: Social gathering
Next Installfest:
TBD
Latest News:
Oct. 10: LUGOD Installfests coming again soon
Page last updated:
2001 Dec 30 16:57

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
Re: [vox-tech] pthread_cond_timedwait and timespec struct
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [vox-tech] pthread_cond_timedwait and timespec struct


  • Subject: Re: [vox-tech] pthread_cond_timedwait and timespec struct
  • From: Richard Cook <rcook@lMAPSlnl.gov>
  • Date: Thu, 28 Sep 2000 16:51:50 -0700
  • References: Pine.GSO.3.96.1000928152656.19554B-100000@wheel.dcn.davis.ca.us

Jeff Newmiller wrote:
> 
> On Thu, 28 Sep 2000, Richard Cook wrote:
> 
> > Jeff Newmiller wrote:
> > >
> > > On Thu, 28 Sep 2000, Richard Cook wrote:
> > >
> > > > Anyone know why pthread_cond_timedwait doesn't seem to wait at all
> > > > (noone sends a cond_signal) for the following snippet?  I guess maybe
> > > > I'm doing something wrong with  TIA
> > > >
> > > >   struct timespec theTimeSpec = {0};
> > > >   theTimeSpec.tv_sec = 0;
> > > >   theTimeSpec.tv_nsec = 500000000;/* 500.0 milliseconds */
> > > >   err = pthread_cond_timedwait(&pcbReadyForSorter_cond,
> > > > &sortWaiting_lock,
>answer:
>   pthread_mutex_lock(&mut);
>   gettimeofday(&now);
>   timeout.tv_sec = now.tv_sec + 5;
>   timeout.tv_nsec = now.tv_usec * 1000;
>   retcode = 0;
>   while (x <= y && retcode != ETIMEDOUT) {
>     retcode = pthread_cond_timedwait(&cond, &mut, &timeout);
>   }
>   if (retcode == ETIMEDOUT) {
>     /* timeout occurred */
>   } else {
>     /* operate on x and y */
>   }
>   pthread_mutex_unlock(&mut);
> ------
> 
> > > As for ETIMEDOUT, the only instance of this macro to be found in my
> > > include tree is in /usr/include/pi-source.h, which is for Pilot
> > > programming.  I think this is a deficiency in the pthreads library.
> >
> > I found a definition in /usr/include/sys/errno.h
> 
> Definitely not in mine.  Bizarre... my man page is more complete than
> yours, but your headers are more up-to-date than mine.

thanks for the sample code.  I also found a function, at:
http://www.transarc.ibm.com/Library/documentation/dce/1.1/pthread_get_expiration_np.html
which does pretty much what you listed all-in-one, but it's cool you
show the error checking as well.
Also, it's weird that ETIMEDOUT is defined in errno.h but you don't
check errno against ETIMEDOUT, you check the return value of
pthread_cond_timedwait... :-|

opinions expressed here are not those of my employer!  
email: rcook@llnl.gov          Rich Cook, Mail Stop L-551 Bldg-3577
Rm-1000
http://www.llnl.gov/graphics   Lawrence Livermore National Laboratory
phone (925) 423-9605 (work)    7000 East Avenue
fax (925) 423-9338             Livermore, CA 94550, USA


LinkedIn
LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
facebook
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
O'Reilly and Associates
For numerous book donations.