C programming guidelines
To take advantage of HCL Informix® database server architecture, you must use the DataBlade® API and follow the guidelines in the Informix® DataBlade® API Programmer's Guide when you write user-defined routines in C.
The Informix® database server uses virtual processors (VPs) to service multiple client-application SQL requests. The database server breaks the SQL request into distinct tasks, based on the resource that the task requires. Different VP types, called virtual processor classes (VP classes), service different kinds of tasks.
The CPU virtual processor (CPU VP) acts as the central processor for client-application SQL requests. When a client application establishes a connection, the CPU VP creates the session thread for that client application. A CPU VP runs multiple session threads to service multiple SQL client applications. Because a session thread is the primary thread for the processing of SQL requests, any C routines in an SQL request normally execute in the CPU VP. However, your routine must be well-behaved by following certain guidelines to avoid loss of performance and data.
- Preserve concurrency by following these rules:
- Yield the CPU VP regularly by using the mi_yield() DataBlade® API function.
- Do not use blocking I/O calls.
- Be thread safe by following these rules:
- Do not use heap-memory allocation; instead use the DataBlade® API memory-management functions.
- Do not modify global or static data; instead use the MI_FPARAM structure to preserve state information.
- Do not modify the global state of the CPU VP.
- Do not use unsafe operating system calls that might impair concurrency or allocate local resources.
Some of these restrictions are relaxed if you assign your routine to a user-defined virtual processor. A user-defined virtual processor is a VP that you create. It runs only those routines that you assign to it.
The Informix® DataBlade® API Programmer's Guide describes in detail each of these guidelines and their possible workarounds with user-defined virtual processors.