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

<bugzilla version="5.0.6"
          urlbase="https://bugzilla.yoctoproject.org/"
          
          maintainer="it-coreprojects-helpdesk@linuxfoundation.org"
>

    <bug>
          <bug_id>8552</bug_id>
          
          <creation_ts>2015-10-21 10:27:40 +0000</creation_ts>
          <short_desc>[glibc] pthread_mutex_unlock return 1 when PTHREAD_PRIO_INHERIT attribute is set on the mutex</short_desc>
          <delta_ts>2016-01-06 09:42:12 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>7</classification_id>
          <classification>Build System, Metadata &amp; Runtime</classification>
          <product>Meta-yocto</product>
          <component>meta-yocto</component>
          <version>2.0</version>
          <rep_platform>x86</rep_platform>
          <op_sys>Multiple</op_sys>
          <bug_status>VERIFIED</bug_status>
          <resolution>NOTABUG</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>Medium+</priority>
          <bug_severity>major</bug_severity>
          <target_milestone>2.1 M1</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Andreas Hansson">pahansson73</reporter>
          <assigned_to name="Juro Bystricky">juro.bystricky</assigned_to>
          <cc>akuster</cc>
    
    <cc>bogdanx.a.voiculescu</cc>
    
    <cc>poky.bs.watcher</cc>
    
    <cc>poky.watcher</cc>
          
          <qa_contact name="Bogdan Alexandru Voiculescu">bogdanx.a.voiculescu</qa_contact>
          <cf_os>---</cf_os>
          <cf_regression_type>---</cf_regression_type>
          
          <cf_docchange>No (bug/feature does not impact docs)</cf_docchange>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>55546</commentid>
    <comment_count>0</comment_count>
      <attachid>2809</attachid>
    <who name="Andreas Hansson">pahansson73</who>
    <bug_when>2015-10-21 10:27:40 +0000</bug_when>
    <thetext>Created attachment 2809
Test program to reproduce the bug

In test program there are three threads involved. The main thread creates two threads that ends up waiting for an event with a call to pthread_cond_wait. The main thread then calls pthread_cond_broadcast to wake the threads up. The main thread releases the lock, then takes the lock again. The last time the main releases the lock, pthread_mutex_unlock return error 1. Also, one of the threads is still blocked by the lock, this is not correct. 

If I comment out the line 

pthread_mutexattr_setprotocol(&amp;mta, PTHREAD_PRIO_INHERIT);

The error disappears.

So my conclusion is that something is broken with the mutex implementation for 32-bit arm architecture.

I build everything on a host running Fedora 21.

Steps to reproduce:

Add this to local.conf

MACHINE = &quot;qemuarm&quot;
KERNEL_IMAGETYPE  = &quot;zImage&quot;
SDKMACHINE = &quot;x86_64&quot;
IMAGE_FEATURES += &quot;ssh-server-dropbear&quot;


# Then build the minimal image
bitbake core-image-minimal
# Build the SDK
bitbake core-image-minimal -c populate_sdk

Expected behavior
If everything works fine, like on x86 architectures, the output of the attached test program is

$ ./test_cond2 
Thread started 
Thread started 
thread : pthread_cond_wait: 0
Thread exit 
thread : pthread_cond_wait: 0
Thread exit 
pthread_mutex_lock return: 0 (should be 0)
Exit Counter 2 (Should be 2)
pthread_mutex_unlock return: 0 (should be 0)


If I run the test program on raspberrypi, the output will be
# ./test_cond2
Thread started
Thread started
thread : pthread_cond_wait: 0
Thread exit
pthread_mutex_lock return: 0 (should be 0)
Exit Counter 1 (Should be 2)
pthread_mutex_unlock return: 1 (should be 0)


I have tested this on a number of different architectures and two different versions of yocto. Please see the table below.

Tests on yocto fido branch (glibc 2.21) (b74ea963cefffad9fbd91d4eb9b240f6a8c86cd0)

Architecture              Bug exists?
---------------------------------------------------
qemuarm                  YES
qemuarm64                NO
qemu386                  NO


Tests on yocto master branch (glibc 2.22) (8578bc17b54da97d42b257b3c8f398ac52b91a9f)

Architecture              Bug exists?
---------------------------------------------------
qemuarm                  YES
raspberrypi              YES
qemuarm64                NO
qemu386                  NO


Tests on raspbian with kernel 4.1.7 and glibc 2.13:

Running test_cond2 on raspbian works just fine. However, if I copy the rootfs from the yocto build above (raspberrypi variant) and chroot to that directory, it doesn’t work, the bug is triggered!

I am not sure if this bug report belongs in the yocto project? Please tell me if you think it should be filed for example in the glibc project instead.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>56670</commentid>
    <comment_count>1</comment_count>
    <who name="Juro Bystricky">juro.bystricky</who>
    <bug_when>2015-11-19 23:31:20 +0000</bug_when>
    <thetext>It looks a lot like the problem reported here:

https://sourceware.org/bugzilla/show_bug.cgi?id=18463</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>56676</commentid>
    <comment_count>2</comment_count>
    <who name="Juro Bystricky">juro.bystricky</who>
    <bug_when>2015-11-20 21:45:10 +0000</bug_when>
    <thetext>Both Fido and Jethro compile glibc with --enable-kernel=2.6.32
The glibc code is explicit:

/* The ARM kernel before 3.14.3 may or may not support
   futex_atomic_cmpxchg_inatomic, depending on kernel
   configuration.  */
#if __LINUX_KERNEL_VERSION &lt; 0x030E03
# undef __ASSUME_FUTEX_LOCK_PI
# undef __ASSUME_REQUEUE_PI
# undef __ASSUME_SET_ROBUST_LIST
#endif

So there is no PI futex support with this configuration.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>56679</commentid>
    <comment_count>3</comment_count>
    <who name="Juro Bystricky">juro.bystricky</who>
    <bug_when>2015-11-22 01:08:16 +0000</bug_when>
    <thetext>I could reproduce the problem for arm.
To verify my assumption, I then rebuilt qemuarm (Jethro) with the following in local.conf:

OLDEST_KERNEL=&quot;3.15.1&quot;

This fixed the problem.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>56680</commentid>
    <comment_count>4</comment_count>
    <who name="Juro Bystricky">juro.bystricky</who>
    <bug_when>2015-11-22 02:02:59 +0000</bug_when>
    <thetext>This behaviour is by design, so it is not a bug.
(Although the design reasons do not seem obvious or intuitive)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>57559</commentid>
    <comment_count>5</comment_count>
    <who name="Bogdan Alexandru Voiculescu">bogdanx.a.voiculescu</who>
    <bug_when>2016-01-06 09:42:12 +0000</bug_when>
    <thetext>Verified as not a bug since this is the design.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>2809</attachid>
            <date>2015-10-21 10:27:40 +0000</date>
            <delta_ts>2015-10-21 10:27:40 +0000</delta_ts>
            <desc>Test program to reproduce the bug</desc>
            <filename>test_cond2.cpp</filename>
            <type>text/x-c++src</type>
            <size>1869</size>
            <attacher name="Andreas Hansson">pahansson73</attacher>
            
              <data encoding="base64">LyoKICogQnVpbGQgbGlrZSB0aGlzIHdpdGggeW9jdG8gU0RLCiAqICMgU291cmNlIGVudmlyb25t
ZW50IAogKiAgICAuIC9vcHQvcG9reS8xLjguMS9lbnZpcm9ubWVudC1zZXR1cC1hcm0xMTc2anpm
c2hmLXZmcC1wb2t5LWxpbnV4LWdudWVhYmkKICogIyBCdWlsZAogKiAgICRDQyAtV2FsbCAtbHB0
aHJlYWQgLW8gdGVzdF9jb25kMiB0ZXN0X2NvbmQyLmNwcAogKi8KI2luY2x1ZGUgPHN0ZGlvLmg+
CiNpbmNsdWRlIDxwdGhyZWFkLmg+CiNpbmNsdWRlIDx1bmlzdGQuaD4KI2luY2x1ZGUgPHN0ZGJv
b2wuaD4KCnN0cnVjdCBTdGF0ZQp7CiAgcHRocmVhZF9tdXRleF90KiBtdXRleDsKICBwdGhyZWFk
X2NvbmRfdCogY29uZGl0aW9uOwogIGludCBleGl0Q291bnRlcjsKfTsKCnZvaWQgKiBsb2NraW5n
VGhyZWFkKHZvaWQqIGRhdGEpCnsKICBTdGF0ZSogc3RhdGUgPSAoU3RhdGUqKWRhdGE7CiAgcHRo
cmVhZF9tdXRleF9sb2NrKHN0YXRlLT5tdXRleCk7CiAgcHJpbnRmKCJUaHJlYWQgc3RhcnRlZCBc
biIpOwogIGludCBlID0gcHRocmVhZF9jb25kX3dhaXQoc3RhdGUtPmNvbmRpdGlvbi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