Multithread Barcode Reading
Overview
To perform barcode recognition, Aspose.BarCode for C++ provides class BarCodeReader that relies on machine vision algorithms. Such algorithms are suitable for parallel execution, and as such, allow speeding up the recognition process by utilizing several CPU cores simultaneously.
To perform multithread barcode reading, class BarCodeReader provides a group of properties called ProcessorSettings that can be used to set all necessary parameters to optimize CPU core usage. Such parameters are initialized globally for all BarCodeReader objects and in most cases do not require additional tuning.
In Aspose.BarCode for C++, multithreading is based on the system parameter called ThreadPool; therefore, to enable efficient use of multithreading, it is necessary to set minimal and maximal values of available cores through system methods SetMinThreads and SetMaxThreads, respectively.
Manual Multithread Recognition Settings
To define multithread recognition settings manually, the following parameters can be used:
- UseAllCores and UseOnlyThisCoresCount are intended to indicate the maximal number of additional CPU cores allowed for use in a single reading operation while identification of the required number of threads is performed automatically for each concrete case.
- MaxAdditionalAllowedThreads is used to set the maximal number of threads allowed for simultaneous execution across all BarCodeReader instances in case of necessity during multithread recognition. Usually, it is recommended to set the value that is twice larger than the value of UseOnlyThisCoresCount or twice greater than the overall number of CPU cores when UseAllCores is set to True.
Single-Thread Recognition
In cases when there is a reason not to use additional CPU cores and to perform single-thread barcode recognition, this can be implemented by setting corresponding parameters UseAllCores, UseOnlyThisCoresCount, and MaxAdditionalAllowedThreads of class ProcessorSettings.
Using Fixed Number of Cores for Recognition
To fix the number of CPU cores that can be allocated for barcode recognition, it is required to apply specific settings to multithreading parameters UseAllCores, UseOnlyThisCoresCount, and MaxAdditionalAllowedThreads of class ProcessorSettings.
Automated Settings with Allocating Maximal Capacity for Recognition
To set automated allocation of the maximal possible number of cores for barcode recognition, the following settings need to be applied. In this case, class BarCodeReader defines the number of required cores without the need for explicit manual instructions.