<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: "Courier New"; mso-no-proof: yes;"><span style="mso-spacerun: yes;"><span style="color: #000000;"> </span></span><span style="color: blue;">if</span><span style="color: #000000;">( dpy->lock && dpy->lock->mutex )<br /></span></span><span style="font-size: 10pt; font-family: "Courier New"; mso-no-proof: yes;"><span style="mso-spacerun: yes;"><span style="color: #000000;"> assert</span></span><span style="color: #000000;">( pthread_mutex_lock(dpy->lock->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: "Courier New"; 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: "Courier New"; mso-no-proof: yes;"><span style="color: #000000;">Then re-ran the app - and hit the assert from OurFn()--><span style="font-size: 11pt; font-family: "Calibri","sans-serif"; 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;">--></span></span><span style="font-size: 11pt; font-family: "Calibri","sans-serif"; 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: "Courier New"; mso-no-proof: yes;"><span style="color: #000000;">
<p><span style="font-size: 11pt; font-family: "Calibri","sans-serif"; 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: "Courier New"; 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: "Courier New"; 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: "Courier New"; 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: "Courier New"; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> ...<br /> </span>shminfo->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: "Courier New"; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </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: "Courier New"; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> ... 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: "Courier New"; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </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: "Courier New"; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>SyncHandle();</span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: "Courier New"; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </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? Should LockDisplay() 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>