singleton

Loki Factory-Singleton throws “dead reference detected” in try-catch-block on ARM

你。 提交于 2019-12-24 07:31:04
问题 I am using Loki SingletonHolder in combination with Loki Factory in my project. The following example basically consists of two lines of code in the try-block to 1.) use the factory 2.) then throw an exception. #include <iostream> #include <loki/Singleton.h> #include <loki/Factory.h> class AbstractBase {}; class ConcreteChild : public AbstractBase {}; class TestFactory: public Loki::SingletonHolder< Loki::Factory<AbstractBase, std::string> > {}; template <class T> T* createNew() { return new

Android mediaplayer singleton service won't stop playing

风格不统一 提交于 2019-12-24 06:58:10
问题 I need to have background music in all my activities. It should stop when the application is not foreground. As I'm developing for 2.3 I can't use the ActivityLifeCycleCallBacks class. I implemented the solution at Checking if an Android application is running in the background and then decided to make the mediaplayer a singleton and use it in a service. Everything works fine and if I press home, select quit from the menu or I make the application go background any way the sound stops but...

How can I a get singleton from Guice that's configured with runtime parameters?

倾然丶 夕夏残阳落幕 提交于 2019-12-24 06:49:43
问题 My overall goal is to load properties from a properties file and then inject those properties into my objects. I would also like to use those properties to instantiate certain singleton classes using Guice. My singleton class looks like this: public class MainStore(){ private String hostname; @Inject public void setHostname(@Named("hostname") String hostname){ this.hostname = hostname; } public MainStore(){ System.out.println(hostname); } } I'm trying to instantiate a singleton using this

How can I trigger a function at Main from an instanced object — the right way?

时间秒杀一切 提交于 2019-12-24 06:47:09
问题 I want to keep total control over my game from the Main MovieClip and nowhere else. But I don't want to pass its instance through constructors neither do any .parent reference thingy from its children. Seems too workaroundish and unstable. A sample situation: public class Main extends MovieClip { public function Main() { addChild(new MainMenu()); } public function startGame():void { trace("Game started"); } } public class MainMenu extends Sprite { public function MainMenu() { var option

Does this redeem a thread-safe Double-Checked Locking pattern?

雨燕双飞 提交于 2019-12-24 04:52:15
问题 The problems with the original Double-Checked Locking pattern have been well-documented: C++ and the Perils of Double-Checked Locking. I have seen the topic come up in questions on SO fairly often. I have come up with a version that, to me, seems to solve the race condition problem of the original pattern, but does it look ok to you? In the code below, I assume that LOCK is a properly implemented mutex type that causes a memory barrier at it's lock/unlock, and I don't attempt to deal with the

does something need to hold a reference to a singleton objective-c object in order to preserve it through the life of an IOS app?

会有一股神秘感。 提交于 2019-12-24 04:05:23
问题 does something need to hold a reference to a singleton objective-c object in order to preserve it through the life of an IOS app? For example if if AppDelegate you created/instantiated a singleton object but didn't retain it, would this instance (with instance variable data) be available later on in the iPhone app? In other words to ensure data in the singleton remains intact, in the App Delegate where it was initially created, would the App Delegate need to retain it to one of it's instance

Which is a better singleton implementation?

孤街浪徒 提交于 2019-12-24 03:36:27
问题 I was looking at these two implementations of the Singleton Pattern: Class Customer { int x; static int count = 0; private Customer() { x = 1; } public static Customer GetCustomer() { if(count==0) { count++; return new Customer(); } else { return null; } } } Implementation 1 in which the constructor is not called if the class is already instantiated once. OR Class Customer{ int x; static int count = 0; public Customer() { if(count == 0) { x = 1; count++; } else { return; } } Implementation 2

Why must the new() constraint require a public constructor?

岁酱吖の 提交于 2019-12-24 03:27:32
问题 Disclaimer: Theoretical Question The new constraint specifies that any type argument in a generic class declaration must have a public parameterless constructor. Source: http://msdn.microsoft.com/en-us/library/sd2w2ew5(v=vs.80).aspx What if I wanted my generic class to have a protected parameterless constructor instead? For instance, if I want to write a Singleton class which I "attach" to other classes to make them Singleton s, I don't want the derived classes to be instantiable - everything

Why must the new() constraint require a public constructor?

纵饮孤独 提交于 2019-12-24 03:27:20
问题 Disclaimer: Theoretical Question The new constraint specifies that any type argument in a generic class declaration must have a public parameterless constructor. Source: http://msdn.microsoft.com/en-us/library/sd2w2ew5(v=vs.80).aspx What if I wanted my generic class to have a protected parameterless constructor instead? For instance, if I want to write a Singleton class which I "attach" to other classes to make them Singleton s, I don't want the derived classes to be instantiable - everything

Lazy initialization of Singleton implementation without using Synchronized Key word

蹲街弑〆低调 提交于 2019-12-24 02:05:50
问题 I was asked in an interview to suggest a design/implementation of a Singleton Pattern where I have to Lazy load the class and also not use the synchronized key word. I got choked and could not come up with anything.I then I started reading on java concurrency and concurrentHaspMap. Please check the below imlpementation and kindly confirm if you see any issue with Double check Locking or any other issues with this implementation. package Singleton; import java.util.concurrent.ConcurrentHashMap