public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libobjc/38307]  New: Calling of the +initialize method is not completely thread-safe
@ 2008-11-28 16:14 rfm at gnu dot org
  2008-12-08  8:40 ` [Bug libobjc/38307] " rfm at gnu dot org
                   ` (4 more replies)
  0 siblings, 5 replies; 13+ messages in thread
From: rfm at gnu dot org @ 2008-11-28 16:14 UTC (permalink / raw)
  To: gcc-bugs

When the first attempt to use a class is made, the +initialize method is
supposed to be called automatically and safely.  The current code check to see
whether +initialize needs to be called by seeing if the dispatch table is
installed.  If the table is not installed, it installs the dispatch table and
calls +initialize using locking to prevent another thread from trying to do the
same thing, but there is a problem ... once the dispatch table for the class
has been installed, it is possible for another thread to use the class before
+initialize completes (ie before the method has had a chance to set up all the
class variables).  This is a rare race condition, but when it occurs it's
extremely hard to recognise and track down.

I think the fix is reasonably straightforward: when this occurs we need to
refrain from installing the dispatch table until +initialize has completed, but
we must make sure that the initializing thread is able to call methods of the
class while it is executing.  The obvious way to do this is to set up a copy of
the dispatch table and have the method lookup use that copy (but only if
locking permits) if there is no installed dispatch table.  Upon completion of
+initialize, the copy is installed as the normal dispatch table so that all
threads can use it.  Unfortunately I haven't had time to implement/test such a
fix yet.


-- 
           Summary: Calling of the +initialize method is not completely
                    thread-safe
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libobjc
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: rfm at gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38307


^ permalink raw reply	[flat|nested] 13+ messages in thread
[parent not found: <bug-38307-4@http.gcc.gnu.org/bugzilla/>]

end of thread, other threads:[~2011-05-25 18:56 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-11-28 16:14 [Bug libobjc/38307] New: Calling of the +initialize method is not completely thread-safe rfm at gnu dot org
2008-12-08  8:40 ` [Bug libobjc/38307] " rfm at gnu dot org
2009-01-01 15:04 ` rfm at gnu dot org
2009-04-10 12:43 ` ayers at gcc dot gnu dot org
2009-04-10 12:44 ` ayers at gcc dot gnu dot org
2009-04-16 19:08 ` pinskia at gcc dot gnu dot org
     [not found] <bug-38307-4@http.gcc.gnu.org/bugzilla/>
2011-03-16 12:47 ` rfm at gnu dot org
2011-03-16 13:34 ` ayers at fsfe dot org
2011-03-17  7:14 ` rfm at gnu dot org
2011-03-17  8:15 ` ayers at fsfe dot org
2011-03-17 20:30 ` rfm at gnu dot org
2011-04-03  4:41 ` rfm at gnu dot org
2011-05-25 18:59 ` nicola at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).