Virtualization and Swift 6

There are some async/await methods in Virtualization; however there's also the ability to specific DispatchQueue.

  • What's the guidance on using these all safely?
  • What are use cases for specifying specific DispatchQueues?

There are some async/await methods in Virtualization; however there's also the ability to specific DispatchQueue. What's the guidance on using these all safely?

The queue safety model with the runtime objects is that all methods must be called on the same queue the virtual machine was created with.

If you create a VZVirtualMachine without creating a queue, the queue to use for all access is the main queue / main actor. If you specify a specific queue at creation, that queue should be used for all method calls.

With Swift async/await usage, the two most common models are either:

  • Use the main actor for all interactions with the runtime objects, like VZVirtualMachine
  • Use an actor with a queue as a custom executor, and use the queue for all interactions with the object.

What are use cases for specifying specific DispatchQueues?

This really depends on the needs and design of the application.

Some applications manage their VMs and all related interactions in a single execution context, using the queue passed to the VMs.

Others are using the main queue for the VM and handle blocking access by dispatching on separate actors.

thank you for the details.

do you have any guidance or documentation for me to look at regarding this:

Use an actor with a queue as a custom executor, and use the queue for all interactions with the object.

I'm not aware of how define a a queue as a custom executor on an actor.

Virtualization and Swift 6
 
 
Q