Opened 14 years ago

Closed 14 years ago

#228 closed defect (fixed)

RNG is not Singleton

Reported by: Peter Owned by: Jari Häkkinen
Priority: major Milestone: yat 0.4
Component: build Version: trunk
Keywords: Cc:

Description (last modified by Jari Häkkinen)

We allow construction through the compiler generated copy constructor.

This is extra severe since the destructor destroys the instance, which is illustrated by this code snippet

RNG* rng=RNG::instance();
rng->seed_from_devurandom();

RNG* rng2 = new RNG(*rng);
std::cout << rng2->name() << std::endl;
delete rng2;

std::cout << rng->name() << std::endl;

Change History (4)

comment:1 Changed 14 years ago by Jari Häkkinen

Status: newassigned

comment:2 Changed 14 years ago by Jari Häkkinen

Description: modified (diff)

comment:3 Changed 14 years ago by Jari Häkkinen

There is also a flaw in that the destructor is public! Anyone can delete the content of the supposedly singleton RNG, but the instance_ is not reset to NULL. This would allow creation of new RNG singletons, but all active RNG*'s would become invalid.

All constructors should be private, and the destructor must also be private.

comment:4 Changed 14 years ago by Jari Häkkinen

Resolution: fixed
Status: assignedclosed

(In [852]) Fixes #228.

Note: See TracTickets for help on using tickets.