<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>25138</bug_id>
          
          <creation_ts>2009-04-10 16:32:51 -0700</creation_ts>
          <short_desc>Need to change WTF::isMainThread() for pthreads to work correctly for thread-specific destructors</short_desc>
          <delta_ts>2009-04-23 14:14:36 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>Web Template Framework</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>Mac</rep_platform>
          <op_sys>OS X 10.5</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>DUPLICATE</resolution>
          <dup_id>25348</dup_id>
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Dmitry Titov">dimich</reporter>
          <assigned_to name="Dmitry Titov">dimich</assigned_to>
          <cc>ap</cc>
    
    <cc>aroben</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>117200</commentid>
    <comment_count>0</comment_count>
    <who name="Dmitry Titov">dimich</who>
    <bug_when>2009-04-10 16:32:51 -0700</bug_when>
    <thetext>Pthreads run destructors of thread-specific data  after thread exits from its thread proc. On non-DARWIN or CHROMIUM flavors of pthreads-based ports, this causes the ThreadIdentifier to be removed from the WTF ThreadMap before those destructors are run. Because of this, the check in isMainThread():
return currentThread() == mainThreadIdentifier;
will insert the new ThreadIdentifier for the exiting thread which will not be removed from the map and cause asserts later in establishIdentifierForPthreadHandle when a new thread with the same thread ID will be created (pthreads reuse their ids).

Fixed with replacing the check with
return pthread_equal(pthread_self(), mainThreadPthreadID);

Since other platform use other methods of dealing with TLS, this is pthread-only fix.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>117201</commentid>
    <comment_count>1</comment_count>
      <attachid>29409</attachid>
    <who name="Dmitry Titov">dimich</who>
    <bug_when>2009-04-10 16:35:57 -0700</bug_when>
    <thetext>Created attachment 29409
Proposed patch</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>117202</commentid>
    <comment_count>2</comment_count>
      <attachid>29409</attachid>
    <who name="Darin Adler">darin</who>
    <bug_when>2009-04-10 16:51:51 -0700</bug_when>
    <thetext>Comment on attachment 29409
Proposed patch

Seems OK to fix isMainThread this way assuming we can live with not being able to fix currentThread().

But what about use of the currentThread() function in thread-specific destructors? Is there a way we can fix that?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>117216</commentid>
    <comment_count>3</comment_count>
    <who name="Dmitry Titov">dimich</who>
    <bug_when>2009-04-10 17:30:03 -0700</bug_when>
    <thetext>(In reply to comment #2)
&gt; (From update of attachment 29409 [review])
&gt; Seems OK to fix isMainThread this way assuming we can live with not being able
&gt; to fix currentThread().
&gt; 
&gt; But what about use of the currentThread() function in thread-specific
&gt; destructors? Is there a way we can fix that?
&gt; 

I&apos;m not sure how to fix currentThread(), especially considering the order of thread-specific destructors is unspecified and pthread_t ids can be reused right after the previous thread using it is finally terminated. Perhaps it&apos;s better to say the ThreadIdentifier is undefined outside of the create/detach lifespan.

Since we don&apos;t use currentThread() now in the thread-specific destructors, I think it would be useful to have a currentThread() return -1 and ASSERT if called outside of create/detach thread lifetime or if it is not the thread that&apos;s called initializeThreading(). This way, the threads from embedder created outside of WTF would not get assigned WTF ThreadIdentifier, nor create a problem with cleaning those out of the ThreadMap (since they wouldn&apos;t use WTF::detachThread). Also, it would actively discourage using currentThread() in thread-specific destructors in the future.

If there will be a need to use WTF threading functions on threads created outside of WTF, we can always add something like WTF::initializeThreadingForCurrentThread with requirement to call detachThread later to reclaim WTF. 

Do you find this a reasonable direction? 
</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>117318</commentid>
    <comment_count>4</comment_count>
      <attachid>29409</attachid>
    <who name="Dmitry Titov">dimich</who>
    <bug_when>2009-04-13 11:21:34 -0700</bug_when>
    <thetext>Comment on attachment 29409
Proposed patch

removing the r? since this needs more work.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>118539</commentid>
    <comment_count>5</comment_count>
    <who name="Dmitry Titov">dimich</who>
    <bug_when>2009-04-23 14:14:36 -0700</bug_when>
    <thetext>Resolving this one as a duplicate of 25348, since that one solves the same issue in a more complete way.

*** This bug has been marked as a duplicate of 25348 ***</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>29409</attachid>
            <date>2009-04-10 16:35:57 -0700</date>
            <delta_ts>2009-04-13 11:21:34 -0700</delta_ts>
            <desc>Proposed patch</desc>
            <filename>patch.txt</filename>
            <type>text/plain</type>
            <size>1978</size>
            <attacher name="Dmitry Titov">dimich</attacher>
            
              <data encoding="base64">ZGlmZiAtLWdpdCBhL0phdmFTY3JpcHRDb3JlL0NoYW5nZUxvZyBiL0phdmFTY3JpcHRDb3JlL0No
YW5nZUxvZwppbmRleCBlNzYyY2M4Li4xMDYyMmFkIDEwMDY0NAotLS0gYS9KYXZhU2NyaXB0Q29y
ZS9DaGFuZ2VMb2cKKysrIGIvSmF2YVNjcmlwdENvcmUvQ2hhbmdlTG9nCkBAIC0xLDMgKzEsMTQg
QEAKKzIwMDktMDQtMTAgIERtaXRyeSBUaXRvdiAgPGRpbWljaEBjaHJvbWl1bS5vcmc+CisKKyAg
ICAgICAgUmV2aWV3ZWQgYnkgTk9CT0RZIChPT1BTISkuCisKKyAgICAgICAgaHR0cHM6Ly9idWdz
LndlYmtpdC5vcmcvc2hvd19idWcuY2dpP2lkPTI1MTM4CisgICAgICAgIENoYW5nZSBXVEY6Omlz
TWFpbl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KTsKICNlbmRpZgogfQogCg==
</data>

          </attachment>
      

    </bug>

</bugzilla>