singleton

destructor of static class need a mutex?

We have a static (singleton) class which will be used in a mutithreaded environment. We use mutex in its constructor and other mrmber functions. However there is no mutex for the destructor. Destructor do some tasks like cleaning up of some other member objetcs etc. Do we need to a mutex in the distructor also ? ...

What's wrong with this fix for double checked locking?

So I've seen a lot of articles now claiming that on C++ double checked locking, commonly used to prevent multiple threads from trying to initialize a lazily created singleton, is broken. Normal double checked locking code reads like this: class singleton { private: singleton(); // private constructor so users must call instance() ...

Why isn't my DbNull a singleton when I deserialise it using XmlSerialiser?

I've always assumed that DbNull.value was a singleton. And thus you could do things like this: VB.NET: If someObject Is DbNull.Value Then ... End if C#: If (someObject == DbNull.Value) { ... } But recently, I serialised a DbNull instance using the XmlSerialiser and suddenly it wasn't a singleton any more. Type comparison o...

How could be implemented Singleton, which populates its values from db in C# ?

I am trying to implement the Jon Skeet's example public sealed class Singleton { Singleton() { } public static Singleton Instance { get { return Nested.instance; } } class Nested { // Explicit static constructor to tell C# compiler // not to mark type as beforefieldinit ...

An obvious singleton implementation for .NET?

I was thinking about the classic issue of lazy singleton initialization - the whole matter of the inefficiency of: if (instance == null) { instance = new Foo(); } return instance; Anyone who knows what a Singleton is is familiar with the issue(you only need the if once). It's trivial but irritating. So, I thought of an alternate ...

C# working with singleton from two different threads

I am using the singleton pattern in a wpf app, but having doubts about how to make it work with multiple threads. I have a class called Monitor which maintains a list of "settings" to watch, for different "devices". Outline shown below. On my main thread I am doing Monitor.getMonitor.register(watchlist) or Monitor.getMonitor.unregist...

Threading and Singletons

Before anyone flips out on me about singletons, I will say that in this instance it makes sense for me to have a singleton given the wide use of this object throughout my code and if someone has a better way short of DI I would like to hear but I would hope that this would not be the focus of this post, moreso helping solve it would be. ...

How can I configure Structuremap to auto scan type in Assembly and Cache by Singleton?

I am using mvc.net with StructureMap to scan and register all repositories and services for me. Now I want to register and cache by Singleton. How can I do? Thanks... IContainer container = new Container(x => { // Register Repositories and Services x.Scan(y => { y.AssemblyContainingType<SomeRepos...

VB.Net Iniatialising a class using System.Reflection and System.Type to create a session based singlton extension method.

I have had several occasions recently to access a specific class several times over a relatively small time frame. So I've been storing the value of the class in Session and trying to access it on page load, if it's not available creating a new instance and storing that in session. So instead of constantly replicating the same code for...

Singleton example

Gang of four uses a load balancer example to demonstrate the singleton pattern. I'm just wondering why a singleton needs to be used in that example? Are there any other real examples that specifically demonstrate using a singleton pattern? I just want to know more specific reasons why I would want to prevent the creation of more than o...

Why do singletons pervade ActionScript culture?

I have recently started doing some ActionScript/Flex programming and I am... Surprised... By the number of singletons I see. They are everywhere! The standard library, the frameworks... Heck, I even read a blog post this morning where the author mentioned that he refactored some of his classes INTO singletons! Is there any reasonable ex...

Unexpected Singleton class behavior on iPhone, am I doing something wrong?

Hey All, I'm implementing a singleton class as follows: static Singleton* _singletonInstance; @implementation Singleton +(void)initialize { _singletonInstance = [[Singleton alloc] init]; } +(Singleton*)instance { return(_singletonInstance); } initialize only gets called the first time someone calls instance. I then have ...

What does "singleton modeless" mean?

I know what a singleton is, but while walking through a web-app, my co-worker said "singleton-modeless". What does he mean by this? ...

Are Singletons really that bad?

It's understandable that many design patterns can in some cases be abused, and like mom always said: "Too much of a good thing isn't always good!" I'm noticing that these days, I'm using Singletons a lot, and I'm worried that I might be abusing the design pattern myself, and running deeper and deeper into a bad-practice kind of habit. ...

Thread implemented as a Singleton

Hi all, I have a commercial application made with C,C++/Qt on Linux platform. The app collects data from different sensors and displays them on GUI. Each of the protocol for interfacing with sensors is implemented using singleton pattern and threads from Qt QThreads class. All the protocols except one work fine. Each protocol's run func...

Singleton Design

I'm creating a game that uses cards. I have an AppController class with one instance in the nib. The AppController instance has an NSArray instance variable called wordList. On init, the nib's instance of AppController generates a new GameCard. Every gamecard has an array of words containing 5 words selected at random from the the list i...

Should all the fields in a GlobalSettings modelling class be static ( C# centric ) ?

The idea is that the ApplicationSettings class will get some default values from a configuration / resource file and later on some but not all from those settings will be applied to UserSettings ...

Can a Singleton Class inside a DLL be shared across processes?

I am creating a custom .net hardware framework that will be used by other programmers to control some hardware. They will add a reference to our DLL to get to our hardware framework. I am in need of a shared class that will be accessed from multiple applications (processes). The singleton pattern seems to be what I need but it only wor...

Assigning a protocol to an NSMutableDIctionary?

Hi all, I am using a singleton backbone in my application to handle accuring errors. They will be handled inside the singleton and broadcast a notification throughout the app when the error has been fixed. Anyways this is not what my question is about but when I pass a new error to the singleton object like this [[SingletonErrors share...

Singleton with Arguments in Java

I was reading the Singleton article on Wikipedia and I came across this example: public class Singleton { // Private constructor prevents instantiation from other classes private Singleton() {} /** * SingletonHolder is loaded on the first execution of Singleton.getInstance() * or the first access to SingletonHold...