Rainer Weikusat wrote:
> Noob wrote:
>
>>> CLOCK_MONOTONIC
>>> The identifier for the system-wide monotonic clock, which is
>>> defined as a clock measuring real time, whose value cannot be set
>>> via clock_settime() and which cannot have negative clock jumps.
>>> The maximum possible clock jump shall be implementation-defined.
>>
>> Question #2 : so how does one deal with the problem of using
>> clock_settime, while several CLOCK_REALTIME-based time-outs
>> are expected?
>
> Conceptually, there no such problem: They're supposed to expired when
> 'the current time' has progressed to a specific datum.
Thing is, I don't care about the "current time".
Conceptually, when I say "try to take this lock for 10 seconds,
either succeed or give up when the time is up", the current time
is not important, all I care about is that the operation should
not block more than 10 seconds (and not less than 10 seconds,
unless I have successfully taken the lock).
As a matter of fact, the POSIX language for clock_settime:
Setting the value of the CLOCK_REALTIME clock via clock_settime()
shall have no effect on threads that are blocked waiting for a
relative time service based upon this clock, including the
nanosleep() function; nor on the expiration of relative timers based
upon this clock. Consequently, these time services shall expire when
the requested relative interval elapses, independently of the new or
old value of the clock.
seems to allow platforms to provide an extension of sem_timedwait
and/or pthread_mutex_timedlock whereby the extended functions would
wait for a relative CLOCK_REALTIME-based duration.
I'm using Linux, are there any such extensions?
Otherwise, as a work-around, I suppose I could set a timer which
would fire a signal, and use a blocking operation, but I'd have
to deal with the races created by splitting the atomic op.
> If some
> 'entity' changes the realtime clock via clock_settime to some value,
> it is the problem of that someone to ensure that it is correct
Errr, so what do you propose? When the system boots, its notion
of the current time is completely wrong. We start the main app,
and "some time later" I manage to get a better idea of the
current time. I suppose I could leave the system in its wrong
view of space and time, but it interacts with the outside, and
I'm afraid that stuff like checking the validity of certificates
will mysteriously fail if the system is stuck in 1970, or whatever
the default is.
Regards.