Write threadsafe code
A well-behaved C UDR must be threadsafe.
During execution, an SQL request might travel around the different VP classes. For example, a query starts in the CPU VP, but it might migrate to a user-defined VP to execute a UDR that was registered for that VP class. In turn, the UDR might fetch a smart large object, which would cause the thread to migrate to the AIO VP.
- Contents of the VP system registers
- Program counter, which contains the address of the next instruction to execute.
- Stack pointer, which points to private memory, called a thread
stack
For more information about use of the thread stack by a UDR, see Manage stack space.
When a thread migrates from one VP to another, it releases its original VP so this VP can execute other threads. The benefit of releasing the CPU VP outweighs the overhead involved in saving the thread state. Therefore, a C UDR must be able to continue execution without loss of information when it migrates to a different VP.
- Does not perform any dynamic memory allocation with operating-system calls
- Does not modify global or static data
- Does not modify other global process-state information