At the moment, when a script thread wants to create a new layout thread, it sends a message to one of the existing layout threads asking for it to spawn. It would be simpler just to provide the script thread with a layout thread factory, and would also deal with the corner case where a script thread has no attached layouts, but is asked to create a layout thread.
cc @jdm