Re: nanosleep over multiple processes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]


On Fri, 22 Jun 2012, Randi Botse wrote:

> Hi All,
> In nanosecond precision, if I have multiple processes run nanosleep(),
> how possbile they will get the same struct timespec value? both the
> tv_sec and tv_nsec value. Of course the tv_sec (second) is most
> possible, but how about the tv_nsec (nanosecond)?
> I wan't to create a simple stupid unique id or something like that,
> but with without too much effort. The unique id will be tv_sec +
> tv_nsec.
while it is highly unlikely that they get the same tv_nsec it is not
impossible so it will not make for a good ID. The problem with such
an ID is simply that if you have a collision then it will be very hard
to debug this situation. Even worse this solution would not be portable
at all - it even could work on one box (e.g. a UP system where the
processes never execute physically concurrent) and fail on a MP in
rare cases - portability to other OS would also be very shaky at the
concept level (even if the API were pure POSIX).

there are unique objects available to any process, pid, address (if
address space randomization is enabled), /dev/random|/dev/urandom
fetching a long long from there is far more reliable than generating
a shaky long long from tv_nsecs (where the upper bits will almost
surely match).

let us know what you need it for and it is easiert to give some suggestions.

To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at

[Index of Archives]     [Linux Assembler]     [Git]     [Kernel List]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [C Programming]     [Yosemite Campsites]     [Yosemite News]     [GCC Help]

  Powered by Linux