newbie dll/random number questions

  • Thread starter Newsgroup Posting ID
  • Start date
N

Newsgroup Posting ID

i'm writing a dll that generates a lot of server console output and as it
will be loaded by several server tasks at the same time the dll output from
all those tasks will be intermixed so i'd like to tag each output line with
an 'id' (generated at dll load time) to identify which lines belong together
(came from the same task).

i've tried using the system time (including milliseconds) but it's not
enough, occasionally i can see two loads that were started in the same
millisecond, i thought of adding a random number to the end to break them up
but as these are being seeded with the (same) load time they end up
generating the same random number.

is there another way i can uniquely identify them?

thanks
 
K

Kevin Easton

Newsgroup Posting ID said:
i'm writing a dll that generates a lot of server console output and as it
will be loaded by several server tasks at the same time the dll output from
all those tasks will be intermixed so i'd like to tag each output line with
an 'id' (generated at dll load time) to identify which lines belong together
(came from the same task).

i've tried using the system time (including milliseconds) but it's not
enough, occasionally i can see two loads that were started in the same
millisecond, i thought of adding a random number to the end to break them up
but as these are being seeded with the (same) load time they end up
generating the same random number.

is there another way i can uniquely identify them?

This is a question about windows, not C, I'm afraid - so you'll probably
get a better answer if you ask in a windows programming newsgroup (look
under the comp.os.* hierarchy). However many operating systems keep a
unique id per task - what about using this task / process id ?

- Kevin.
 
N

Newsgroup Posting ID

hi,

i can't, this is for a dll, it gets loaded by the task(s), the counter in
the dll would never increment as the dll itself is never loaded more than
once per task, (the dll code itself is loaded just once and each task that
loaded the dll gets a seperate data storage area) thats why i was looking
for a real random number generator, something i could add to the system time
to make it unique

thanks
 
I

Irrwahn Grausewitz

Newsgroup Posting ID said:
hi,

i can't, this is for a dll, it gets loaded by the task(s), the counter in
the dll would never increment as the dll itself is never loaded more than
once per task, (the dll code itself is loaded just once and each task that
loaded the dll gets a seperate data storage area) thats why i was looking
for a real random number generator, something i could add to the system time
to make it unique

thanks

Your question is still off-topic in c.l.c, so please refer to a more
suitable ng, like Kevin already suggested.

However: using random number generators to produce unique ids is a very
bad idea for obvious reasons: how would you guarantee that no two
instances will produce the same number at the same time by chance?

Regards

Irrwahn
 
K

Kevin Easton

Newsgroup Posting ID said:
hi,

i can't, this is for a dll, it gets loaded by the task(s), the counter in
the dll would never increment as the dll itself is never loaded more than
once per task, (the dll code itself is loaded just once and each task that
loaded the dll gets a seperate data storage area) thats why i was looking
for a real random number generator, something i could add to the system time
to make it unique

I can only assume this is in reply to my reply, since you didn't leave
any context. But I didn't say anything about a counter - I said to use
the task / process ID that your OS assigns to each task / process -
which is necessarily unique across tasks / processes. You'll have to go
ask in a Windows programming newsgroup to find out how to get this,
though.

- Kevin
 
J

Jack Klein

i'm writing a dll that generates a lot of server console output and as it
will be loaded by several server tasks at the same time the dll output from
all those tasks will be intermixed so i'd like to tag each output line with
an 'id' (generated at dll load time) to identify which lines belong together
(came from the same task).

i've tried using the system time (including milliseconds) but it's not
enough, occasionally i can see two loads that were started in the same
millisecond, i thought of adding a random number to the end to break them up
but as these are being seeded with the (same) load time they end up
generating the same random number.

is there another way i can uniquely identify them?

thanks

Neither C nor C++ have DLLs. DLLs are a mechanism of your operating
system, not defined or supported by either of the languages discussed
here. If you want to talk about DLLs, you need a Windows programming
group or one that supports your particular brand of Window compiler.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top