Parallel lua seemingly not running parallel

They’re running on different threads, but one seems to be… just… waiting for the other one to do its thing?


All of the other threads I looked at look like this too.

Here’s my code, each script is parented under a different actor:

script 1
game:GetService("RunService").RenderStepped:Connect(function()
	task.desynchronize()
	
	debug.profilebegin("Actor 1 Desync")

	print("Actor 1 Desync")
	
	debug.profileend()
	
	task.synchronize()
	
	debug.profilebegin("Actor 1 Sync")
	
	print("Actor 1 done")
	
	debug.profileend()
end)
script 2
game:GetService("RunService").RenderStepped:Connect(function()
	task.desynchronize()
	
	debug.profilebegin("Actor 2 Desync")
	
	print("Actor 2 Desync")
	
	debug.profileend()
	
	task.synchronize()
	
	debug.profilebegin("Actor 2 Sync")
	
	print("Actor 2 done")
	
	debug.profileend()
end)
Instance hierarchy
![image|170x94](upload://xiPnoiDLHAISDfwxMWQ1pBgJ2m.png)

Looks like the image isnt loading at the time of typing this, if it isnt loading for you:
StarterPlayerScripts
   Actor1
      LocalScript
   Actor2
      LocalScript

Could anyone explain why one is just hanging until the other one finishes? Am I misunderstanding something here?

Not sure what you’re asking here.

From what I’m reading, I assume you’re asking why some threads wait for other threads before running. If so, this is because synchronized threads will wait for parallel threads to finish executing before they will, provided they’re in the same actor.

A possible different problem could be that you’re desynchronizing in the actor, which does the opposite of desynchronizing outside the actor. Desynchronizing inside an actor synchronizes with the main thread (and vice versa), causing code to run in series instead of parallel. I may be wrong, as you’re not connecting parallel in the actor scripts.

As for your first paragraph, notice the images. Every thread looks like that, where there are two threads, one with actor 1 desync and another with actor 2 desync. Notice that despite being in different threads, one just hangs for a while until the other finishes printing, and then calls the print function.

As for the second one, that doesn’t appear to be the case after some experimentation. Sync puts them on the main thread and desync puts them on other threads, even when called inside of actors.

I’m suspecting that print statements work differently. The behaviour in question is that you must wait for the previous print to finish before the next print can run, even though it’s in a different actor/thread.

I tested this theory by adding multiple actors (more than 2), and the hypothesis was proven correct.


Three actors:

image


Four actors:

1 Like

You’re right, it probably is the case that print works differently. Ill experiment later today with that.