A
A. Farber
Hello,
I'm programming a web game on OpenBSD, but am
also trying to keep in runnable on Linux and Cygwin.
I have a list of tables at which a player/kibitzer can
sit down or create a new empty one if (s)he wants.
I keep tables in a doubly-linked list using the nice TAILQ_* macros:
http://www.openbsd.org/cgi-bin/man.cgi?query=queue
and later I'd like to switch to red-black hashes - the RB_* macros in:
http://www.openbsd.org/cgi-bin/man.cgi?query=tree
(for Linux and Cygwin I just copy OpenBSD's tree.h and queue.h).
MY PROBLEM is to get a unique id for a newly allocated
table structure. Here are the options I've considered:
1) Using epoch seconds - is not nice, race condition
2) Using a random number - not nice, same as above
3) Using a sequential number - I'd have to cycle through
my whole doubly linked list of tables to verify it is unique
4) Using the id of the creating player - can't do that,
because I don't want to drop all other players/kibitzers
off the table if that 1st player wants to stand up
(and maybe move to another table)
5) Using the address of the newly created table struct -
seems to be ok, but requires a long long type...
Does anybody please have some other idea?
Thank you
Alex
I'm programming a web game on OpenBSD, but am
also trying to keep in runnable on Linux and Cygwin.
I have a list of tables at which a player/kibitzer can
sit down or create a new empty one if (s)he wants.
I keep tables in a doubly-linked list using the nice TAILQ_* macros:
http://www.openbsd.org/cgi-bin/man.cgi?query=queue
and later I'd like to switch to red-black hashes - the RB_* macros in:
http://www.openbsd.org/cgi-bin/man.cgi?query=tree
(for Linux and Cygwin I just copy OpenBSD's tree.h and queue.h).
MY PROBLEM is to get a unique id for a newly allocated
table structure. Here are the options I've considered:
1) Using epoch seconds - is not nice, race condition
2) Using a random number - not nice, same as above
3) Using a sequential number - I'd have to cycle through
my whole doubly linked list of tables to verify it is unique
4) Using the id of the creating player - can't do that,
because I don't want to drop all other players/kibitzers
off the table if that 1st player wants to stand up
(and maybe move to another table)
5) Using the address of the newly created table struct -
seems to be ok, but requires a long long type...
Does anybody please have some other idea?
Thank you
Alex