From bd1e9c7548b41a3c546c5211bb3ffa3d4e8d7f9e Mon Sep 17 00:00:00 2001 From: Leonardo de Moura Date: Thu, 14 Nov 2013 19:06:36 -0800 Subject: [PATCH] feat(lua): throw an exception if the user tries to create a thread and Lean was compiled without multi-threading support Signed-off-by: Leonardo de Moura --- src/bindings/lua/leanlua_state.cpp | 1 + src/util/interrupt.h | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/src/bindings/lua/leanlua_state.cpp b/src/bindings/lua/leanlua_state.cpp index 30c0c75d4..dafde5199 100644 --- a/src/bindings/lua/leanlua_state.cpp +++ b/src/bindings/lua/leanlua_state.cpp @@ -399,6 +399,7 @@ leanlua_thread & to_thread(lua_State * L, int idx) { } int mk_thread(lua_State * L) { + check_threadsafe(); leanlua_state & st = to_state(L, 1); char const * script = luaL_checkstring(L, 2); int first = 3; diff --git a/src/util/interrupt.h b/src/util/interrupt.h index c56bc6bec..79d08921c 100644 --- a/src/util/interrupt.h +++ b/src/util/interrupt.h @@ -62,4 +62,12 @@ public: void join(); bool joinable(); }; + +#ifdef LEAN_THREAD_UNSAFE +inline void check_threadsafe() { + throw exception("Lean was compiled without support for multi-threading"); +} +#else +inline void check_threadsafe() {} +#endif }