Re: [Vala] Singleton question
- From: "Phil Housley" <undeconstructed gmail com>
- To: "Ali Sabil" <ali sabil gmail com>
- Cc: vala-list gnome org
- Subject: Re: [Vala] Singleton question
- Date: Wed, 29 Oct 2008 21:50:51 +0000
2008/10/29 Ali Sabil <ali sabil gmail com>:
You can take a look at this:
http://live.gnome.org/Vala/Tutorial#head-a81a520acce1ad8622b8a2f895177b9765a69841
Also, maybe you should read this:
http://steve.yegge.googlepages.com/singleton-considered-stupid
Since that article has no comments section, I'll say this here: What?
There was really no coherent argument there at all. Singleton is
fine where the size of the project makes it appropriate - for
enterprise level stuff it will cause problems, but how much of life is
that? Used well a singleton represents some functionality that isn't
directly tied to any particular data, while still allowing the
flexibility of OO programming, despite what the article says, of
course you can subclass a singleton, it's just another class after
all.
Anyway, that's not the point of this thread. Basically all you have
to do to make your singleton threadsafe is remember that anyone can
call it at any time, regardless of how long ago they called
get_instance. That means you either have to make sure every call to a
method that can change data is locked (see the tutorial, as Ali said)
or move to an asynchronous model (probably not worth the effort unless
some singleton operations are really very long.)
Phil.
--
Ali
On Wed, Oct 29, 2008 at 6:28 AM, "José D. Abad" <granveoduendes gmail com>
wrote:
I used the singleton pattern. For now it has worked.
My question is: How can I make it//// thread-safe with Glib?
________________
using GLib;
public class CSingleton : Object
{
private static CSingleton Instance = null;
private static void CreateInstance ()
{
if (Instance == null)
{
Instance = new CSingleton ();
}
}
public static CEscena Get_Instance ()
{
if (Instance == null) CreateInstance ();
return Instance;
}
}
________________
......
CSingleton singleton = Get_Instance ();
________________
_______________________________________________
Vala-list mailing list
Vala-list gnome org
http://mail.gnome.org/mailman/listinfo/vala-list
_______________________________________________
Vala-list mailing list
Vala-list gnome org
http://mail.gnome.org/mailman/listinfo/vala-list
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]