How EGCS with multi-threaded compliance?
David Lucas
dlucas@checkfree.com
Mon Apr 13 12:28:00 GMT 1998
Just an observastion, but some compilers do not even guarentee that
init_lock will be initialized before the use of f_initialize_a, thus a
possible uninitialized Mutex object.
I would suggest even making the Mutex heap based and maybe use a double
lock pattern of some sort. It can get real tricky in static space.
;-)
> static Mutex init_lock;
> inline A& f_initialize_a()
> {
> static A *a = 0;
> if (!a) {
> Lock lock(init_lock); // released when lock goes out of scope
> if (!a)
> a = new A();
> }
> return *a;
> }
>
> void f() {
> A& a = f_initialize_a();
> }
Later,
Dave
--
-----------------------------------------------------------------
David Lucas | mailto:dlucas@checkfree.com
Staff Software Engineer |
Systems Software Development | My opinions are IMHO.
OFX Server Devl 08-126 |
|
CheckFree Corporation | Work# 614.825.3511
8275 High Street | Fax# 614.825.3104
Columbus, OH 43235 | http://www.checkfree.com
-----------------------------------------------------------------
More information about the Gcc
mailing list