Ignoring thread safety with parallels

You can write your topic however you want, but you need to answer these questions:
I want to change a bones position without syncing it

Roblox decides to think for me, and does not allow me to change the position of the bone while not on the main thread

Is there any way to tell the script to let me do whatever I want?

Note: I am updating thousands of bones at the same time; and when I do that on one thread it lags depending on how many I update.

Second Note: I am never going to be in a situation where I am reading and writing the bone properties at the same time

task.synchronize() -- I DONT want this.
	
for key, bone_data in update_cache do

	bone_data.Bone.Position = bone_data.Position

end
1 Like

No. If it’s not safe to be edited in parallel, you can’t edit it in parallel. It’s like that for a reason, you can’t change it.

Could you expand on why it is like that? Thanks! (Never mind, I forgot the documentation existed)

Do you have any recommendations to help with the lag? Would it be better to have one script that updates all of the bones?

ive spent long typing this ill send it anyway despite documentation (which im pretty sure also does not document why thread safety exists), also please see bottom message

It could lead to errors, inconsistencies, or even deadlocks and crashes.

Let’s take an example: PVInstance:PivotTo(), which is also not safe to be called in parallel. This is because the Roblox core scripts and internals run on the main thread, which is also where your synchronized threads run. Since it’s all run on one thread, one task can’t interfere with another one.

Parallel Luau provides a second thread for your game’s code to run on, and uses an entirely new Luau VM. This is asynchronous to the other thread; the two of them run at the same time. So, if one modifies the pivot while the other is reading it, it could cause a lot of problems due to the inconsistency in the thread reading it.

But it can go a lot deeper than this. Threads may deadlock each other, where neither can proceed with their respective task, eating up memory and causing issues. It can cause many logic errors and errors thrown, and can really mess up your game.

- Roblox Studio Assistant

This is why you must run these things on the main thread.

the info about thread safety and where roblox core and internals run is from the Studio assistant (excluding the quotes), if it’s wrong blame the assistant :wink:

Can you give some more information about your specific situation? Why do you need to update them so often?

I have a custom wave system that I am trying to get to run smoothly. It currently runs every frame, but I had to sacrifice looks. I currently update the bones that are farther away less often, but that adds some whitespace which looks off.

I use a tile system.
Each tile has 25 bones (5x5 grid)
I can run 20x20 tiles fine with the fix above, but as I said, it looks off.

The main performance hit I found was updating the bones. So, if I could update the positions in different threads, then that issue should be solved.

Unfortunately, it appears I cannot do so. :slightly_frowning_face: