External-library routines
It is recommended that a C UDR avoid the use of routines from existing external libraries. Some of these external routines might contain system calls that are restricted in your VP. If your C UDR must use an external routine, it might be ill behaved.
- Routines that do blocking I/O, such as routines that open files
- Routines that dynamically allocate memory, such as malloc()
- Routines that allocate static memory
- Divide the UDR into critical-code sections and DataBlade-API-code sections.
- Execute the UDR in a user-defined VP.
For an external routine to execute safely, the thread that executes the UDR must not migrate out of the VP as long as the UDR uses the unsafe resources (open files, memory allocated with malloc(), or static-memory data). However, DataBlade API functions might automatically yield the VP when they execute. This yielding causes the thread to migrate to another VP.
- Critical-code sections
These sections contain only the external-library calls that are not safe in the CPU VP. Before execution leaves the critical-code section, any unsafe resources must be released: open files must be closed and memory allocated with malloc() must be deallocated.
- DataBlade-API code sections
These sections contain only DataBlade API functions. No external-library functions that are not safe in the CPU VP exist in these sections because any DataBlade API function might cause the thread to migrate.