... and while I think I have determined that I don't need it, I'd like to know if the singleton implementation that I had put together would have had any nasty side-effects that I hadn't considered... as I'm sure that if I keep working directly with device drivers, I'll eventually have a real need for one and I'd like to not have it blow up on me then 
The basics were a singleton TheDevice class with:
A) a private constructor that would open and initialize the device
B) a private destructor that would shutdown and close the device (and unlock the mutex not unlocked when it's called in D below)
C) a protected getInstance function looking something like:
D) a protected releaseInstance function looking something like:
Finally, there would be a Controller class which would be a friend of TheDevice and thus could call getInstance and releaseInstance. Resulting in a Controller class that could be created/destroyed as a normal class, but with only a single instance of the Device class shared by all instances of the Controller class.
The basics were a singleton TheDevice class with:
A) a private constructor that would open and initialize the device
B) a private destructor that would shutdown and close the device (and unlock the mutex not unlocked when it's called in D below)
C) a protected getInstance function looking something like:
Code:
mutex.lock();
if(NULL == theInstance)
{
theInstance = new TheDevice();
}
numReferences++;
mutex.unlock();
return theInstance;
Code:
mutex.lock();
numReferences--;
if(0 == numReferences)
{
delete this;
// following the delete we can no longer reference any (non-static) variables or functions of this class
}
else // need an else, as this code must not be executed after the destructor is called
{
mutex.unlock();
}
Finally, there would be a Controller class which would be a friend of TheDevice and thus could call getInstance and releaseInstance. Resulting in a Controller class that could be created/destroyed as a normal class, but with only a single instance of the Device class shared by all instances of the Controller class.