The nonyielding user-defined VP

A nonyielding user-defined virtual-processor class runs a C UDR in a way that gives the routine exclusive use of the VP. It executes the UDR serially. That is, each UDR runs to completion before the next UDR begins. The C UDR does not yield.

The most common use of a nonyielding user-defined VP class is for porting of legacy code that is not designed to handle concurrency issues (non-reentrant code) or that uses global memory.

The following table summarizes the programming rules that apply to execution in a nonyielding user-defined VP.
CPU VP safe-code requirement Required for nonyielding user-defined VP?
Yields the CPU on a regular basis Not required
Does not use blocking operating-system calls Not required
Does not allocate local resources, including heap memory Yes
Does not modify global or static data Not required (for global changes accessed by a single invocation of the UDR)
Does not modify other global data Not required (for global changes accessed by a single invocation of the UDR)
Does not use unsafe operating-system calls Yes

The main advantages of a nonyielding user-defined VP class is that a single invocation of the UDR is guaranteed to run on the same VP. This restriction creates the following benefits for an ill-behaved routine.

Feature of a nonyielding user-defined VP Benefit to an ill-behaved UDR
Provides the same support for blocking I/O as a yielding user-defined VP A UDR can perform blocking I/O functions. For a list of some sample blocking I/O functions, see Avoid blocking I/O calls.
Can execute a C UDR that was not designed or coded to handle the concurrency issues of multiprocessing A UDR executes to completion. A nonyielding user-defined VP ignores requests for a yield within DataBlade® API functions as well as explicit calls to mi_yield().
Allows your UDR to modify global information A UDR can modify global information (such as global or static variables, or global process information) as long as the changes to this global information are only needed within a single invocation of the UDR.

For more information, see Avoid modification of global and static variables and Modify the global process state.

However, a nonyielding user-defined VP has the following disadvantages:
  • It reduces concurrency of the UDR execution.

    If you have multiple VPs in the nonyielding VP class, multiple instances of the UDR can run concurrently, one per VP. However, each UDR invocation runs to completion. No migration occurs while one UDR invocation executes (or if the UDR performs blocking I/O).

  • It does not guarantee that the state remains across multiple instances of the UDR.

    Two invocations of the UDR might not overlap on the same VP. Therefore, the global VP state remains stable. However, another instance of the UDR might migrate into the VP and change the global VP state.

Important: If your UDR needs to make changes to global information that is available across the UDR instance, you must use a single-instance user-defined VP to execute the UDR.

For more information, see Define a nonyielding user-defined VP class.