Best uses of Parallel Luau?

What are the ways that you create mutex locks between actors?

I just went down a rabbit hole about an hour ago regarding this.

It seems like while you can use mutex lock, you cannot use singletons in the actor design pattern. So you have to craft nify ways using event based methods like what I did in that link. I dont believe this is a bug but rather the side effect of partitioning everything in seprarate VMs. The global context in a VM is not shared with other scripts not in a VM so the only way to share data SharedDataTable with timestamps or send messages as you mentioned using actor event based messaging.

Also, is it possible for a child/worker actor to send information back to the master thread in the same way the master thread talks to the workers using actor:sendMessage?

No not really. This was the weird tricky part. Luckily we have SharedTableRegistry and SharedTable to update data and combination of RemoteEvents to notify master that worker is done and to clean it up and put its id back into the process queue. You really want to use SharedTableRegistry anyway sine its considered parallel safe. And to ensure you dont break the single-write multi-reader problem SharedTable has a CloneAndFreeze method. You COULD consider cloning a table, modifying it in a task.spawn but you run the risk of reading/writing bad data. I believe its bad practice.

1 Like