0

I have a usecase in which I want to acquire a condition variable and release it after some time interval( Eg: I have a queue of time ordered events and I want to block for a specified duration .)

Duration = Earliest Time in Q - Current Time()

I came across the following which would exactly serve my purpose.

 pthread_cond_timedwait(pthread_cond_t *restrict cond,
 pthread_mutex_t *restrict mutex,
 const struct timespec *restrict abstime);

But the problem is timespec.sec is of time_t ( which is a 32 signed type ) and it overflows. Is there a workaround for this ? Is there any other construct available which we will be to block for a longer time ? I am using a Linux platform.

KodeWarrior
  • 3,538
  • 3
  • 26
  • 40

1 Answers1

1

In 64 bit Linux environments, time_t is 64 bit and not 32. The 32 bit time_t will not overflow until the year 2038, so you have a few years left to upgrade your machine.

caf
  • 233,326
  • 40
  • 323
  • 462
  • Yes, In this case the code has to be ported for a 64 bit compiler. pthread_cond_timedwait fails because we pass in a 32 bit type. Is there any similar library which takes in a double for blocking instead of a signed 32 bit type. – KodeWarrior Oct 11 '12 at 09:44
  • 1
    @KodeWarrior: It is nonsensical to say that you are overflowing the `abstime.sec` field of a `pthread_cond_timedwait()` call *today*, because that would mean that you are asking it to wait for more than 25 years. – caf Oct 11 '12 at 09:55
  • I don't understand why it's nonsensical. When u build systems you design them to work for the next 10 days or the next 10 years ? – KodeWarrior Oct 11 '12 at 21:59