Threading and Concurrency
Through the use of multithreading, the CBFS class provides powerful concurrency features to help applications maximize their performance. For data integrity purposes, the class also strictly enforces the order in which events fire in certain situations, and allows applications to specify the extent to which events should be fired concurrently.
Please note that, even when configured for minimal concurrency, the class always fires events in the context of some worker thread, not in the thread the class was originally created on. Therefore, applications must be sure to synchronize operations between event handlers and other threads as necessary (including, but not limited to, calls to the class instance, unless a method is explicitly documented as callable within events).
Configuring Event Concurrency
Generally speaking, the CBFS class will always enforce per-file event serialization; that is, it always fires events relating to the same file in sequence (though technically-speaking, there is one optional exception to this behavior, discussed at the end of this section). For example, if there are multiple read or write operations pending against a given file, then an event will be fired for the first operation, and after its event handler has returned, another event will be fired for the second operation; and so on.
With per-file event serialization already assured, the most important concurrency-related consideration for CBFS-based applications is whether to enforce multi-file event serialization as well. The class's serialize_events property controls whether events relating to different files should be serialized on a single worker thread, or fired in parallel on several; by default, this property is disabled, and events for different files are allowed to fire in parallel.
When the serialize_events property is disabled, the MinWorkerThreadCount and MaxWorkerThreadCount configuration settings control the minimum and maximum number of worker threads the class can use for firing events. By default, both are set to 0, which indicates that the CBFS system driver should automatically choose appropriate values based on how many CPU cores the system has. These settings are both ignored if serialize_events is enabled.
As mentioned previously, the CBFS class offers one feature that alters its otherwise strictly-enforced per-file event serialization model: the ability to handle non-overlapping read operations on a single file in parallel. This functionality is controlled by the serialize_access property, which is enabled by default. This property is ignored if serialize_events is enabled.