{"action":"created","issue":{"url":"https://api.github.com/repos/NVIDIA/libglvnd/issues/36","labels_url":"https://api.github.com/repos/NVIDIA/libglvnd/issues/36/labels{/name}","comments_url":"https://api.github.com/repos/NVIDIA/libglvnd/issues/36/comments","events_url":"https://api.github.com/repos/NVIDIA/libglvnd/issues/36/events","html_url":"https://github.com/NVIDIA/libglvnd/issues/36","id":85187616,"number":36,"title":"libGLdispatch: Race condition in PatchEntrypoints","user":{"login":"kbrenneman","id":4998757,"avatar_url":"https://avatars.githubusercontent.com/u/4998757?v=3","gravatar_id":"","url":"https://api.github.com/users/kbrenneman","html_url":"https://github.com/kbrenneman","followers_url":"https://api.github.com/users/kbrenneman/followers","following_url":"https://api.github.com/users/kbrenneman/following{/other_user}","gists_url":"https://api.github.com/users/kbrenneman/gists{/gist_id}","starred_url":"https://api.github.com/users/kbrenneman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kbrenneman/subscriptions","organizations_url":"https://api.github.com/users/kbrenneman/orgs","repos_url":"https://api.github.com/users/kbrenneman/repos","events_url":"https://api.github.com/users/kbrenneman/events{/privacy}","received_events_url":"https://api.github.com/users/kbrenneman/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-06-04T17:05:26Z","updated_at":"2015-06-04T17:40:53Z","closed_at":null,"body":"libGLdispatch will try to let a vendor library patch the OpenGL entrypoints when there's a single thread with a current context. When a second thread calls MakeCurrent, then it'll restore those entrypoints to the original versions.\r\n\r\nThat means that the second thread might try to rewrite an entrypoint while the first thread is executing it.\r\n"},"comment":{"url":"https://api.github.com/repos/NVIDIA/libglvnd/issues/comments/108987464","html_url":"https://github.com/NVIDIA/libglvnd/issues/36#issuecomment-108987464","issue_url":"https://api.github.com/repos/NVIDIA/libglvnd/issues/36","id":108987464,"user":{"login":"kbrenneman","id":4998757,"avatar_url":"https://avatars.githubusercontent.com/u/4998757?v=3","gravatar_id":"","url":"https://api.github.com/users/kbrenneman","html_url":"https://github.com/kbrenneman","followers_url":"https://api.github.com/users/kbrenneman/followers","following_url":"https://api.github.com/users/kbrenneman/following{/other_user}","gists_url":"https://api.github.com/users/kbrenneman/gists{/gist_id}","starred_url":"https://api.github.com/users/kbrenneman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kbrenneman/subscriptions","organizations_url":"https://api.github.com/users/kbrenneman/orgs","repos_url":"https://api.github.com/users/kbrenneman/repos","events_url":"https://api.github.com/users/kbrenneman/events{/privacy}","received_events_url":"https://api.github.com/users/kbrenneman/received_events","type":"User","site_admin":false},"created_at":"2015-06-04T17:40:53Z","updated_at":"2015-06-04T17:40:53Z","body":"One possibility that I can think of is to add some scratch space after each entrypoint. The vendor library would write its versions into that scratch space, leaving the original entrypoint unmodified.\r\n\r\nAt the top of each entrypoint, it would then jump to one version or the other.\r\n\r\nIf there were an unconditional branch at the top, then libGLdispatch could rewrite that branch to point to the vendor library's code after the vendor library is finished patching. Restoring the original would just mean rewriting the jump so that it points back to the original code instead.\r\n\r\nAlternately, it could be a conditional branch based on some global flag. Then, restoring the original entrypoints would just mean setting that flag.\r\n\r\nThe first thread (the one executing the entrypoint) will still be using the same context, and thus the same vendor library. As long as it uses one or the other, it'll be fine."}}