NET:Concepts:Frame Locking

From Lavish Software Wiki
Revision as of 20:29, 2 December 2006 by Lax (talk | contribs)
(diff) ←Older revision | view current revision (diff) | Newer revision→ (diff)
Jump to navigation Jump to search

Overview

Frame locking is a term used to describe the act of preventing the host application (e.g. game) from continuing to process information while a section of code executes, by acquiring frame lock. Generally, a frame lock is non-exclusive. This means that other threads will continue to run, and may also have frame lock acquired. The only behavior implied by a frame lock is that the host application will not do any processing that may cause objects in use to disappear. This complements standard thread synchronization functionality. A frame lock must be explicitly released before the frame can continue.

Without acquiring frame lock, there is no guarantee that the executing thread can safely use any objects from the host application. Therefore, APIs are expected to use frame locking internally to enforce safety, and applications are expected to use frame locking to enforce safety across multiple API calls when necessary (for example, when calling one function to acquire an object, and subsequently using the object in such a way that it must be done within the current frame).

Exclusive Locks

Exclusive locking blocks any other thread attempting to acquire frame lock, until the exclusive lock is released -- it does not suspend execution of the other threads, only blocks frame lock attempts. This generally should not be used, as it may deadlock the application if the exclusive locking thread must wait on a resource in use in another thread that attempts a frame lock. Standard thread synchronization should be used instead.

Frame wait

A frame wait will cause a thread to yield execution until the following frame. This can be used instead of System.Threading.Sleep(0) to indicate the shortest yield possible, only continuing when the current frame has ended and the next begun. Frame lock can be implicitly acquired during frame wait.

Frame Locking API

Frame locking API in .NET is implemented in LavishVMAPI.Frame. Equivalent functions with the same names as those in LavishVMAPI.Frame are found in ISInterface for Inner Space extensions.

See Also