rrid_t rascal_init(unsigned int policy);
This function initializes the library. Typically, it creates working threads and several threads for library's internal purposes. If initialization fails, the application should stop interacting with the library; all attempts to call functions that perform asynchronous actions will fail.
There is no function to shut the library down; this only happens when the process ceases.
The policy
parameter defines the behaviour of the library and can be one of the following:
RIP_WORKER_MANUAL
Tells the library not to spawn worker threads. The application must periodically call rascal_work
to perform all outstanding tasks and dispatch events. This mode is useful for applications that have a running loop and want everything – both the non-library code and event dispatching – happen within a single thread.
RIP_WORKER_SINGLE
Tells the library to create a single worker thread that dispatches events "in the background". This mode is useful for applications that serve a GUI in the main thread, such as applications written with MFC or other libraries, and the developer does not want to hack into the main program loop to call rascal_work
from there.
This is the recommended mode of execution for most GUI applications and applications that don't fight for best performance.
RIP_WORKER_PER_CPU
Tells the library to launch as many worker threads as there are CPUs installed. On systems that support it, affinity masks are set so that each thread runs on a different CPU. This mode is best for high-performance applications.
In a multithreaded environment the application must use its own means to protect the data from being accessed simultaenously by multiple threads.