Skip to content

concurrent/parallel processing in lua #494

Answered by khvzak
mrxsisyphus asked this question in Q&A
Discussion options

You must be logged in to vote

In both options you will achieve similar level of concurrency. In send mode the lock is released when a Future returns Pending which allow to schedule many futures (task_fn.call_async) concurrently.

The LocalSet approach is more efficient simply because it's lock-free. From the tokio perspective and from Lua perspective as well.

However, to achieve true parallelism (i.e. ability to run Lua code in parallel; without depending on yielding points) you would need to run many Lua VMs (ideally one per thread) to use them in parallel.
You can pass data between VMs using serialization or by sharing memory (e.g. a userdata object like Arc<Mutex<HashMap<K, V>>>) that can be safely accessed by all VMs.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by mrxsisyphus
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #490 on December 01, 2024 13:05.