Add hardware_threads() function (#111)

* Add hardware_threads() function
This commit is contained in:
Ilia 2018-10-17 12:54:41 +03:00 committed by mihacooper
parent d189d67349
commit c5d94ec465
3 changed files with 11 additions and 0 deletions

View File

@ -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)

View File

@ -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
);

View File

@ -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'