Re: Question about static class objects

From: Tom Roberts <tjrob_at_fnal.gov>
Date: Tue, 27 May 2008 13:34:35 -0500


Yes, that code will very likely have problems in a multi-threaded program. It will be OK iff you can ensure that just a single thread at a time calls Zap::list(). For multi-threaded operation the accessor function is a rather poor design, and one would normally derive a class from TList that applies a mutex to the appropriate class functions....

I have no need or desire for multiple threads. Note that writing a program to be thread safe involves overheads, and can be rather complicated, so one does it only when necessary.

Tom Roberts

Konstantin Olchanski wrote:
> On Tue, May 27, 2008 at 12:01:57PM -0500, Philippe Canal wrote:

>> TList &Zap::list() {
>>    static TList list;
>>    return list;
>> } 
>> which anyway is slightly better in term of C++ style :)

>
>
> This will bomb in a multi-threaded program?
>
>
Received on Tue May 27 2008 - 20:36:13 CEST

This archive was generated by hypermail 2.2.0 : Tue May 27 2008 - 23:50:01 CEST