msys.shareSet
Last updated March 2020
Name
msys.shareSet — Associate a value with a keystring in the global share space
Synopsis
msys.shareSet(keystring, value);
keystring: string value: string
Description
This function associates a value with keystring
in the global share space. This association is thread-safe and consistent across all Lua interpreters and co-routines. The act of setting the value is thread safe and does not require an explicit mutex, but it is recommended that you use a mutex to coordinate modification of the value. value
may be a number, string, boolean or nil value.
Note
This function has been made obsolete by the data sharing features introduced in version 3.2. For more information see msys.runInPool.
... incrementing a counter in a thread safe manner msys.lock("counter-example"); local c= msys.shareGet("my-counter"); if c == nil then c = 0; end msys.shareSet("my-counter", c + 1); msys.unlock("counter-example");
Because this function is in the msys
namespace, an explicit require
is not necessary.
See Also
Was this page helpful?