Boost logo

Boost :

From: Andy (atompkins_at_[hidden])
Date: 2007-06-04 13:18:16


Other than the current approach (which I agree is not acceptable), I see
6 alternatives to the uuid::create() function. I believe all of them
have been mentioned before.

1. Make the random number generator a static object. Document the
function as not thread safe. This will be fast, but easy to use
incorrectly (e.g. in a multi-threaded program).

2. Make the random number generator a static object and protect calls to
it with a mutex. This is a thread safe solution, but it will be slow
because of the mutex.

3. Make the random number generator live in thread local storage. This
will be a thread safe solution, but requires Boost.Thread.

4. Use the current seed as the random numbers directly. Will this
solution provide 'good' uuids? That is, is this source of random numbers
good enough?

5. Create a function object (that has the random number generator as a
member) that produces uuids. Is this too complicated?
i.e.:
class uuid_generator {
public:
  uuid_generator() {
    engine.seed(get_seed());
  }
  uuid operator() const;
private:
  Engine& engine;
};

6. Create a CAS/lock-free random number generator. This is hard to
implement.

I am favoring number 4, unless it will not produce good uuids. Then I
favor number 5.

I guess I am looking for direction as to how to proceed.

Andy.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk