Need help with Parallel Luau

Heyy devs! How’re going?

So I tried to start using Parallel Luau and testing it, but I can’t use it properly. I receive that error on the output:

Event GuiButton.MouseButton1Click is not safe to access in parallel  -  Client - FrameModule:25

The code:

function module:_refresh(TABLE): {}
	self.FRAMES = table.clone(TABLE)
	table.clear(self.FRAMES)
	task.desynchronize()
	for _, v in pairs(TABLE) do
		if FramesParent:FindFirstChild(v.Name) then
			self.FRAMES[v.Name] = FrameModule.new(v.Name) -- when it is called, there is a MouseButton1Click function inside it
			print(v.Name)
		end
	end
	task.synchronize()
	return self.FRAMES
end

print(self:_refresh(self.BUTTONS))

From what it looks, you are using desynchronize where synchronize should be used. You will want synchronize to be first, as you want that event (MouseButton1Click) to run in Serial not Parallel.

Little bit of an edit
task.synchronize() is used to Serialize- Parallel code,
task.desynchronize() is used to Parallelize- serialized code.

If whatever calls _refresh is not already running in Parallel, there is no need to Serialize for the MouseButton1Click event.

Please note that I am pretty bad at parallel Luau, but from what I know about it, you could just try to synchronize it back into serial before the mousebutton1click function, or you could move the mousebutton1click function somewhere else in the module that is running in serial.

Take a grain of salt with what I’m gonna say, since I am not adept at Parallel Luau.

There are some functions or events that are not safe to be called in a code that is parallel or desynchronized. In particular, events of Instances and such are not safe to be called in parallel luau, though there may be Instances exempted from this.

I have no knowledge on how you can deal with this problem. There may be resources and forums that may help you. You just have to search for the right keywords.

As others have stated, some properties, methods, and events (it seems like), cannot be written to, or read from, when desynchronize (aka running in parallel)


In the documentation, you want to look for these tags to see if something can be read or written to when desynchronized

Another thing to not is that your use of parallel is not good. Currently, you are only running 1 parallel thread, which means you cannot have multiple parallel threads running at the same time. You can have more parallel threads by having multiple actors running scripts in parallel

Parallel lua can also end up being slower than serial for work that isn’t significant. The overhead of transferring parameters and running the threads in parallel can be bigger than the benefits of running multiple threads at once

While the structure of actors has been made for having separated instances (like npcs), with their script, run in parallel, as of now, very little properties are write safe (as of now), which makes this use case umm not great.
As for running mathematically expensive stuff (aka doing a lot of raycasts, spacial queries, or compression/decompression of really big strings/tables), I have made a module that makes it easier to use, as the actor system isn’t adapted for this use case

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.