diff --git a/README.md b/README.md index ea72e20..2e33489 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,7 @@ Requires C++14 compiler compliance. Tested with GCC 4.9+, clang 3.8 and Visual S * [effil.thread_id()](#id--effilthread_id) * [effil.yield()](#effilyield) * [effil.sleep()](#effilsleeptime-metric) + * [effil.hardware_threads()](#id--effilhardware_threads) * [Table](#table) * [effil.table()](#table--effiltabletbl) * [__newindex: table[key] = value](#tablekey--value) @@ -306,6 +307,11 @@ Suspend current thread. **input**: [time metrics](#time-metrics) arguments. +### `effil.hardware_threads()` +Returns the number of concurrent threads supported by implementation. +Basically forwards value from [std::thread::hardware_concurrency](https://en.cppreference.com/w/cpp/thread/thread/hardware_concurrency). +**output**: number of concurrent hardware threads. + ## Table `effil.table` is a way to exchange data between effil threads. It behaves almost like standard lua tables. All operations with shared table are thread safe. **Shared table stores** primitive types (number, boolean, string), function, table, light userdata and effil based userdata. **Shared table doesn't store** lua threads (coroutines) or arbitrary userdata. See examples of shared table usage [here](#examples) diff --git a/src/cpp/lua-module.cpp b/src/cpp/lua-module.cpp index cabd934..89c5d6a 100644 --- a/src/cpp/lua-module.cpp +++ b/src/cpp/lua-module.cpp @@ -108,6 +108,7 @@ int luaopen_effil(lua_State* L) { "ipairs", SharedTable::globalLuaIPairs, "size", luaSize, "allow_table_upvalues", luaAllowTableUpvalues, + "hardware_threads", std::thread::hardware_concurrency, sol::meta_function::index, luaIndex ); diff --git a/tests/lua/thread.lua b/tests/lua/thread.lua index b4df6ae..ff92c09 100644 --- a/tests/lua/thread.lua +++ b/tests/lua/thread.lua @@ -4,6 +4,10 @@ local effil = effil test.thread.tear_down = default_tear_down +test.thread.hardware_threads = function() + test.is_true(effil.hardware_threads() >= 0) +end + test.thread.wait = function () local thread = effil.thread(function() print 'Effil is not that tower'