From b45bc73aca3183d8c928818d6aa800a51cc9686c Mon Sep 17 00:00:00 2001
From: Andreas Kloeckner <inform@tiker.net>
Date: Wed, 9 Dec 2015 18:43:34 -0600
Subject: [PATCH] Try to make clSetEventCallback callback lambda have stdcall

---
 src/c_wrapper/event.h | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/src/c_wrapper/event.h b/src/c_wrapper/event.h
index 3d6c8769..5c31af4a 100644
--- a/src/c_wrapper/event.h
+++ b/src/c_wrapper/event.h
@@ -40,14 +40,21 @@ public:
         try {
             pyopencl_call_guarded(
                 clSetEventCallback, PYOPENCL_CL_CASTABLE_THIS, type,
-                [] (cl_event, cl_int status, void *data) {
-                    rm_ref_t<Func> *func = static_cast<rm_ref_t<Func>*>(data);
-                    std::thread t([func, status] () {
-                            (*func)(status);
-                            delete func;
-                        });
-                    t.detach();
-                }, (void*)func);
+                static_cast<void (CL_CALLBACK * /* pfn_notify */)(cl_event, cl_int, void *)>(
+                    [] (cl_event, cl_int status, void *data) {
+                        rm_ref_t<Func> *func = static_cast<rm_ref_t<Func>*>(data);
+
+                        // We won't necessarily be able to acquire the GIL inside this
+                        // handler without deadlocking. Create a thread that *can*
+                        // wait.
+
+                        std::thread t([func, status] () {
+                                (*func)(status);
+                                delete func;
+                            });
+                        t.detach();
+
+                    }), (void*)func);
         } catch (...) {
             delete func;
             throw;
-- 
GitLab