SPE run control

After the application has created an SPE context and loaded an SPE program into its local store, it can call spe_context_run to run an SPE context. A thread which executes an SPE context is called an SPE thread.

The API function to run a context is a synchronous, blocking call from the perspective of the thread using it, that is, while an SPE program is executing, the associated SPE thread blocks and is usually put to "sleep" by the operating system. When the SPE program stops, either because it reaches its "normal" exit point, or a stop and signal instruction or an error condition, the spe_context_run function returns and the resulting return value specifies the exact condition under which the SPE program stopped.

Many applications need to use multiple SPEs concurrently. In this case, the application must create at least as many threads, by using standard methods of the operating system, as concurrent SPE contexts are required. Each of these threads may run a single SPE context at a time. If N concurrent SPE contexts are needed, it is, however, common to use N+1 threads; one main (application) thread that "orchestrates" the execution of N SPE threads.

In a multithreaded environment, it is often convenient to use an event mechanism for notification about certain events caused by the asynchronously running SPE threads. A specific event is used to indicate that an SPE context has stopped in the SPE thread. The function spe_stop_info_read allows the main thread to read the full information about why the SPE context stopped.