A fiber is a structure that stores the state of a native code call stack, enabling it to be swapped with that of other fibers. (For a detailed explanation of fibers, please read the Wikipedia article at http://en.wikipedia.org/wiki/Fiber_(computer_science)). This construct has been offered in the Windows operating systems since Windows NT and Windows 95 to facilitate coroutine behavior.
There is no comparable MacOS facility for synchronous stack swapping, so the MacOS versions of AutoCAD cannot rely on such a mechanism at all.
In the context of AutoCAD, fibers have been used extensively in its controller architecture because they provide a very powerful and straightforward way of managing document switching and command execution by swapping native code call stacks within a thread.
To illustrate, consider the example of switching between two documents in a Multiple Document Interface (MDI) environment:
In more detail, the “Application context” described in the ObjectARX MDI API documentation is itself a separate fiber that is “neutral ground” between documents. Each document has at least 2 fibers: one being the main AutoCAD command processor state; the other being the LISP state, thus allowing LISP to use the (command) function to synchronously drive the AutoCAD command processor, without disturbing its own context, which is maintained in a native code stack. To allow ARX-registered commands to also use the global functions acedCommand() and acedCmd() to synchronously drive the AutoCAD command processor, each command runs in its own fiber as well, which allows one ARX-registered command to run another ARX-registered command.
The three main areas where Fibers are used in AutoCAD are:
acedCommand()/acedCmd() in ObjectARX(command) in LISPEach thread also maintains a native code stack on all relevant platforms. In older operating systems, threads were even used for the same purpose that fibers are now, but that was before the introduction of GUI API libraries, whose components strictly enforce being manipulated only on the thread they were created on. For that reason, threads cannot be used to replace fibers in modern operating systems.
All of AutoCAD’s fiber manipulation occurs on the main thread of the application. AutoCAD remains, by default, a single-threaded application, with a few very limited exceptions outside the domain of AutoCAD application development environments.