Reputation: 1015
Is it safe to submit the same object to clock_nanosleep in the request and remain parameters?
do {
ret = clock_nanosleep(CLOCK_MONOTONIC, 0, &t, &t);
} while (ret == EINTR);
I'm currently researching a phenomenon where the system sometimes never leaves that loop (although it usually does).
Regards
Upvotes: 0
Views: 381
Reputation: 67762
Is it safe to submit the same object to clock_nanosleep in the request and remain parameters?
In a POSIX-conforming environment at least, it's fine.
From the POSIX clock_nanosleep
doc,
The rqtp and rmtp arguments can point to the same object.
For LINUX specifically, I can't see anything in my local manpage about this, at least not explicitly prohibiting it. The non-NULL remain
timespec is only written to if the call is already going to return, with an incomplete relative sleep: it doesn't need to read the request timespec again during or after this.
The manpage does additionally say (of the remain timespec)
This value can then be used to call clock_nanosleep() again and complete a (relative) sleep.
in which case it's certainly desirable for clock_nanosleep
to write it back into the same variable.
Upvotes: 1