[Gc] Singleton Question

Renato Tegon Forti re.tf at ieee.org
Sat Jan 13 12:09:06 PST 2007


Hi All,

 

I have one doubt:

 

 

If I have a class structure, like this:

 

      A (: public gc)

      |

 ------------

 |    |     |

 B    C     D

            |

            ------

            |     |

            E     F (singleton class)

 

 

What this can cause?

 

Thanks.

 

 

Referece:

 

      class F : public D

      {

      public:

            static F *instance()

            {

                  static MutexLock mutex;

 

                  if(instance_ == NULL)

                  {

                        // Acquire mutex to block other threads

                        mutex.acquire();

 

                        if(instance_ == NULL)

                        {

                             instance_ = new F();

                        }

 

                        // release mutex to other threads

                        mutex.release();

                  }

 

                  return instance_;

            }

 

            F()

            {

            }

 

            virtual ~F()

            {

            }

 

 

      private:

 

            // Obj Instance

            static F* instance_;

      };

 

F* F::instance_ = NULL;

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://napali.hpl.hp.com/pipermail/gc/attachments/20070113/96e2c636/attachment-0001.htm


More information about the Gc mailing list