Mutex: Difference between revisions

→‎{{header|Wren}}: Further blurb.
(Added Wren blurb.)
(→‎{{header|Wren}}: Further blurb.)
Line 1,286:
As Wren's VM is effectively single threaded (only one fiber can run at a time), mutexes are only relevant for embedded scripts where two or more VMs are being run in parallel by the host and the VMs need shared access to some resource.
 
In such a case the host (see [https://github.com/wren-lang/wren/wiki/Language-Bindings here] for those currently available) would almost certainly deal directly with synchronization using whatever mechanisms were available to it and access to the resource would therefore be transparent as far as the Wren scripts were concerned i.e. the latter would not need to acquire or release a lock on the resource themselves.
 
However, to avoid excessive latency, a VM whose thread were continuing would need to signal to the host that it no longer needed the resource so the lock could be released thereby making it available to the other VM(s). Typically, a shared resource might need to be represented something like this in a Wren script:
 
<lang ecmascript>foreign class Resource {
// obtain a pointer to the resource when available
construct new() {}
 
// method for using the resource
foreign doSomething()
 
// signal to the host that the resource is no longer needed
foreign release()
}
 
var res = Resource.new() // wait for and obtain a lock on the resource
res.doSomething() // use it
res.release() // release the lock</lang>
 
=={{header|zkl}}==
9,490

edits