Creating and Terminating Threads

A virtual device can use the VMMCreateThread service to create a new thread in the system virtual machine. The new thread runs in protected mode at ring three. VMMCreateThread returns a handle identifying the new thread. The virtual device can use the handle in subsequent services which control the execution of the thread, such as Adjust_Thread_Exec_Priority.

Before creating the new thread, VMMCreateThread broadcasts the Create_Thread control message to all virtual devices in the system. A virtual device typically responds by allocating any structures it needs to support the thread. By setting the carry flag, a virtual device that cannot support the new thread can prevent the thread from being created.

After the new thread is created, VMMCreateThread broadcasts the Thread_Init control message to all virtual devices. This message passes the handle of the new thread to the virtual devices, and gives the devices an opportunity to perform initialization procedures that must take place in the context of the new thread.

A virtual device can use the VMMTerminateThread service to destroy a thread created by a previous call to VMMCreateThread. The VMMTerminateThread service will not destroy the initial thread of a virtual machine, nor will it destroy the currently executing thread.

Before terminating a thread, VMMTerminateThread broadcasts the Terminate_Thread control message to all virtual devices. When the thread is no longer being scheduled, the Thread_Not_Executeable control message is broadcast to all virtual devices. Finally, the Destroy_Thread control message is broadcast, signaling that it is safe for virtual devices to free resources associated with the thread.

See also Adjust_Thread_Exec_Priority, Create_Thread, Destroy_Thread, Terminate_Thread, Thread_Not_Executeable, VMMCreateThread, VMMTerminateThread