From: Nicholas Mc Guire <der.herr@hofr.at>
To: Randi Botse <nightdecoder@gmail.com>
Cc: linux-c-programming <linux-c-programming@vger.kernel.org>
Subject: Re: nanosleep over multiple processes
Date: Fri, 22 Jun 2012 07:53:56 +0200 [thread overview]
Message-ID: <20120622055356.GA15833@opentech.at> (raw)
In-Reply-To: <CAA6iF_7rzg8o0C5kbNgcRYmgj=t+0As-YQzP7Ddbmaz6yMAqLA@mail.gmail.com>
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.
thx!
hofrat
next prev parent reply other threads:[~2012-06-22 5:53 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-22 5:07 nanosleep over multiple processes Randi Botse
2012-06-22 5:53 ` Nicholas Mc Guire [this message]
2012-06-22 8:38 ` Randi Botse
2012-06-22 9:08 ` Hendrik Visage
2012-06-23 13:11 ` Vladimir Murzin
2012-06-27 15:44 ` Randi Botse
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20120622055356.GA15833@opentech.at \
--to=der.herr@hofr.at \
--cc=linux-c-programming@vger.kernel.org \
--cc=nightdecoder@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).