<html>
    <head>
      <base href="https://bugs.freedesktop.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - eglGetDisplay() is not thread safe"
   href="https://bugs.freedesktop.org/show_bug.cgi?id=101252">101252</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>eglGetDisplay() is not thread safe
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>Mesa
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>git
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>Other
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux (All)
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>medium
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>EGL
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>mesa-dev@lists.freedesktop.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>eucan@de.adit-jv.com
          </td>
        </tr>

        <tr>
          <th>QA Contact</th>
          <td>mesa-dev@lists.freedesktop.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=131599" name="attach_131599" title="Sample code for reproducing the bug">attachment 131599</a> <a href="attachment.cgi?id=131599&action=edit" title="Sample code for reproducing the bug">[details]</a></span>
Sample code for reproducing the bug

Hello,

We found out this issue in our GPU driver tests. It happens when many threads
are created and every thread creates wl_display object and calls
eglGetDisplay(). Then, some threads are getting EGL_NO_DISPLAY.

I implemented a sample code for reproducing the bug (main.c). The issue occurs
very often when I run the binary with 300 threads. I tried it in mesa 11.2 but
I saw the related code for upstream is the same.

I debugged mesa code and I found out that a thread gets EGL_NO_DISPLAY only
when _eglGetNativePlatform() returns _EGL_INVALID_PLATFORM.

native_platform variable is defined as static in _eglGetNativePlatform().
Therefore, different threads are sharing the same variable. When I remove the
static keyword and recompile mesa binaries, the issue never occurs.

In my platform, EGL_PLATFORM and EGL_DISPLAY env variables are never defined.
Therefore, _eglGetNativePlatformFromEnv() function always returns
_EGL_INVALID_PLATFORM.

I think issue occurs when a thread is in the end of _eglGetNativePlatform()
just before returning found native_platform, and the other thread overwrites
this static variable in _eglNativePlatformFromEnv() function.

Most likely issue is introduced by this commit:
7adb9b094894a512c019b3378eb9e3c69d830edc

Best Regards,
Emre Ucan</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are the assignee for the bug.</li>
          <li>You are the QA Contact for the bug.</li>
      </ul>
    </body>
</html>