Critical Section?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ed S

    #1

    Critical Section?

    HiAll,

    What would you suggest I use if I want to protect the creation of a
    singleton - in the instance() static method. In C++, I'd use a critical
    section.

    Thanks,

    --Ed

  • Alvin Bruney

    #2
    Re: Critical Section?

    say
    lock(this)
    {
    create singleton here
    }

    Locking on this is bad though because some other thread could conceivably
    lock on this creating a deadlock of sorts. But that will give you roughly
    the equivalent of a critical section.
    --


    -----------
    Got TidBits?
    Get it here: www.networkip.net/tidbits
    "Ed S" <esinek.mapso n-a-t-mapson.summatio n.com> wrote in message
    news:eP69ac0nDH A.1672@TK2MSFTN GP09.phx.gbl...[color=blue]
    > HiAll,
    >
    > What would you suggest I use if I want to protect the creation of a
    > singleton - in the instance() static method. In C++, I'd use a critical
    > section.
    >
    > Thanks,
    >
    > --Ed
    >[/color]


    Comment

    • Jay B. Harlow [MVP - Outlook]

      #3
      Re: Critical Section?

      Ed,
      Here is a write up on how to write a Singleton in C#, complete with making
      it thread safe.



      Hope this helps
      Jay

      "Ed S" <esinek.mapso n-a-t-mapson.summatio n.com> wrote in message
      news:eP69ac0nDH A.1672@TK2MSFTN GP09.phx.gbl...[color=blue]
      > HiAll,
      >
      > What would you suggest I use if I want to protect the creation of a
      > singleton - in the instance() static method. In C++, I'd use a critical
      > section.
      >
      > Thanks,
      >
      > --Ed
      >[/color]


      Comment

      Working...