digitalmars.D.learn - Are constructors thread-safe?
- Stefan (19/19) Aug 01 2005 Are constructors thread-safe?
- Stefan (10/29) Aug 01 2005 Hhm, is this such a birdbrained question that no one wants to answer?
- Ben Hinkle (5/50) Aug 01 2005 Unless the ctor touches some static variables like adds itself to a list...
- Stefan (4/61) Aug 01 2005 Thanks Ben, your assessment eases me a lot!
Are constructors thread-safe? In other words, if want to write a thread-safe class, what is the correct way to implement a constructor: A) (constructors are thread-safe) B) (constructors are NOT thread-safe) Any comments highly appreciated! Thanks, Stefan
Aug 01 2005
Hhm, is this such a birdbrained question that no one wants to answer? I've seen D code that does it the option B) way. To me that appears nonsensical since IMO no other thread should be able to obtain a reference to an object before it is fully constructed. So I'm inclined to say that synchronization in constructors is futile as a general rule (access to static members needs to be synchronized, of course). Am I on the right track here? I'm new to D, so please share your thoughts :) Kind regards, Stefan In article <dckp9v$23jg$1 digitaldaemon.com>, Stefan says...Are constructors thread-safe? In other words, if want to write a thread-safe class, what is the correct way to implement a constructor: A) (constructors are thread-safe) B) (constructors are NOT thread-safe) Any comments highly appreciated! Thanks, Stefan
Aug 01 2005
Unless the ctor touches some static variables like adds itself to a list or starts a new thread or something then I agree the synchronized shouldn't be needed. "Stefan" <Stefan_member pathlink.com> wrote in message news:dcm208$emd$1 digitaldaemon.com...Hhm, is this such a birdbrained question that no one wants to answer? I've seen D code that does it the option B) way. To me that appears nonsensical since IMO no other thread should be able to obtain a reference to an object before it is fully constructed. So I'm inclined to say that synchronization in constructors is futile as a general rule (access to static members needs to be synchronized, of course). Am I on the right track here? I'm new to D, so please share your thoughts :) Kind regards, Stefan In article <dckp9v$23jg$1 digitaldaemon.com>, Stefan says...Are constructors thread-safe? In other words, if want to write a thread-safe class, what is the correct way to implement a constructor: A) (constructors are thread-safe) B) (constructors are NOT thread-safe) Any comments highly appreciated! Thanks, Stefan
Aug 01 2005
In article <dcm32p$fou$1 digitaldaemon.com>, Ben Hinkle says...Unless the ctor touches some static variables like adds itself to a list or starts a new thread or something then I agree the synchronized shouldn't be needed.Thanks Ben, your assessment eases me a lot! Regards, Stefan"Stefan" <Stefan_member pathlink.com> wrote in message news:dcm208$emd$1 digitaldaemon.com...Hhm, is this such a birdbrained question that no one wants to answer? I've seen D code that does it the option B) way. To me that appears nonsensical since IMO no other thread should be able to obtain a reference to an object before it is fully constructed. So I'm inclined to say that synchronization in constructors is futile as a general rule (access to static members needs to be synchronized, of course). Am I on the right track here? I'm new to D, so please share your thoughts :) Kind regards, Stefan In article <dckp9v$23jg$1 digitaldaemon.com>, Stefan says...Are constructors thread-safe? In other words, if want to write a thread-safe class, what is the correct way to implement a constructor: A) (constructors are thread-safe) B) (constructors are NOT thread-safe) Any comments highly appreciated! Thanks, Stefan
Aug 01 2005