<p>First post from an X newbie - so please go easy on me :)</p>
<p>There's quite a few recent bug reports around looking similar to this (subject line). <br />I know because I had this occur in our own multi threaded app and have been searching for a solution. (No luck.)</p>
<p>So I figured out that the only way this assert could occur is if _XAllocID was being called without LockDisplay() in effect. So I added an assert in XAllocID to try and find the offending caller:</p>
<p><span style="font-size: x-small; color: #0000ff;"><span style="font-size: x-small; color: #0000ff;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;"><span style="color: #000000;">&nbsp;&nbsp;&nbsp; </span></span><span style="color: blue;">if</span><span style="color: #000000;">( dpy-&gt;lock &amp;&amp; dpy-&gt;lock-&gt;mutex )<br /></span></span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;"><span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; assert</span></span><span style="color: #000000;">(&nbsp;pthread_mutex_lock(dpy-&gt;lock-&gt;mutex) == EDEADLK );</span></span></span></span></p>
<p><span style="font-size: x-small; color: #0000ff;"><span style="font-size: x-small; color: #0000ff;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"></span></span></span><span style="font-size: x-small; color: #0000ff;"><span style="font-size: x-small; color: #0000ff;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="color: #000000;">Then re-ran the app - and hit the assert from OurFn()--&gt;<span style="font-size: 11pt; font-family: &quot;Calibri&quot;,&quot;sans-serif&quot;; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA;">XShmAttach() <span style="font-size: x-small; font-family: Courier New;">--&gt;</span></span><span style="font-size: 11pt; font-family: &quot;Calibri&quot;,&quot;sans-serif&quot;; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA;">_XAllocID () </span></span></span></span></span></p>
<p><span style="font-size: x-small; color: #0000ff;"><span style="font-size: x-small; color: #0000ff;">
<p><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="color: #000000;">
<p><span style="font-size: 11pt; font-family: &quot;Calibri&quot;,&quot;sans-serif&quot;; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA;">
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">libXext::XShmAttach looks like this...<br /></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">Status XShmAttach(Display *dpy, XShmSegmentInfo *shminfo)</span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">{</span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; ...<br />&nbsp;&nbsp;&nbsp; </span>shminfo-&gt;shmseg = XAllocID(dpy);</span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; </span>LockDisplay(dpy);</span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; ... some stuff ...</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; </span>UnlockDisplay(dpy);</span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; </span>SyncHandle();</span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">return</span> 1;</span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;">}</p>
<p>Is this a bug in XShmAttach?&nbsp;Should LockDisplay()&nbsp;be moved before the XAllocId() line...?<br />Or is it the XShmAttach caller's responsibility to lock the display?<br />I made and tested a patch with LockDisplay moved before XAllocID and it definitely fixed our problem.</p>
</span></p>
</span></span></p>
</span></span></p>