Warning: Can't synchronize with repository "(default)" (/home/git/ome.git does not appear to be a Git repository.). Look in the Trac log for more information.
Notice: In order to edit this ticket you need to be either: a Product Owner, The owner or the reporter of the ticket, or, in case of a Task not yet assigned, a team_member"

Bug #1383 (closed)

Opened 15 years ago

Closed 15 years ago

static ObjectFactory access in OmeroCpp may need a mutex

Reported by: jamoore Owned by: jamoore
Priority: minor Cc: bernhard.hollaender@…
Sprint: n.a.
Total Remaining Time: n.a.

Description

From Bernhard:

A colleague of mine has tried to create clients in parallel
threads, this caused a segfault while accessing the objectfactories
map. Could it be that you need to mutex the objectFactories method? If
one thread added some keys already, while another is accessing the
partial filled map leads to missing keys. I could be something
different though, as I know that you have a mutex in the client code
above the access to the objectFactories method.

Change History (2)

comment:1 Changed 15 years ago by jmoore

From Bernhard:

I just read a thread on comp.lang.c++ about threads and singleton
initialization. They suggested the following:

As Bart van Ingen Schenau and James Kanze have said, it's thread-safe
as is, but there's the static initialization order problem. Generally,
you solve this problem either with library support ala pthread_once,
or you make your singleton instance be a function local static to
"initialize on demand" to solve the static initialization order
problem, and then you make a global whose sole purpose is to
initialize the singleton before main(), and thus presumably before
there are threads. (If there are nontrivial threads before main, you
cannot solve this problem with mutexes alone in C++. You would need
the power of pthread_once or equivalent.)

Ex:

//hpp
class singleton
{
public:
    static singleton& getSingleton();

};

//cpp
singleton& singleton::getSingleton()
{   static singleton * x = new singleton;
    return *x;
}

namespace { bool forceInit = (singleton::getSingleton(), true); }

See http://groups.google.com/group/comp.lang.c++/browse_frm/thread/9007b1aacad2022e?hl=en
for details.

comment:2 Changed 15 years ago by jmoore

  • Resolution set to fixed
  • Status changed from new to closed

r5498 refactors the RTypes object factory registration. I never reproduced the issue, so let me know if it persists.

Note: See TracTickets for help on using tickets. You may also have a look at Agilo extensions to the ticket.

1.3.13-PRO © 2008-2011 Agilo Software all rights reserved (this page was served in: 0.67964 sec.)

We're Hiring!