Joined: Tue Oct 17, 2006 6:06 pm Posts: 1437 Location: Vancouver, BC, Canada
|
You also have to make sure that getInstance() is either protected by a lock of some kind, or is first called with interrupts disabled (in case interrupt handlers call getInstance()) before any threads are created. Or you do what I do and have a separate init() method that gets called very early in kernel initialization before getInstance() is ever called. This is one reason why I try to avoid implementing Singleton with a pointer instead of a global object whenever possible (but in my kernel, it's not really possible because I need a predictable order of initialization).
_________________ Top three reasons why my OS project died:
- Too much overtime at work
- Got married
- My brain got stuck in an infinite loop while trying to design the memory manager
Don't let this happen to you!
|
|