Coroutines
Although it doesn't support classical multithreading techniques (i.e. multiple simultaneous preemptively scheduled threads accessing a shared program state), MiniD does provide a simpler, safer, and more efficient alternative called collaborative multithreading. In this model, only one thread is ever executing at once, meaning that it does not improve instruction bandwidth. However, you still get most of the conceptual benefits of multithreading by splitting up your program into logical tasks.
Besides allowing you to split up your program's work into multiple independent threads, coroutines are also lightweight enough to make it possible to use them for such tasks as iteration and filtering. In this way they can function as something like a more powerful version of a function closure, where they save not only the function's data state, but also the function's execution state.
Basics
First let's go over some general information about MiniD's coroutine model. A coroutine (or thread) is an object which represents a thread of execution. You can have as many threads as you want, but only one can be executing at any given time. All threads have their own local state (own call stack and local variables) but share the same global state. Because of the restriction that only one thread may be running at any time, it is impossible to have race conditions when dealing with the shared global state, and therefore the headaches and complexity imposed by things like semaphores, mutexes, condition variables, barriers, monitors etc. are completely avoided.
MiniD's threads also have the concept of a "main function." This is the function which will be executed when the thread is first started.
fffff
