Journal "Software Engineering"
a journal on theoretical and applied science and technology
ISSN 2220-3397
Issue N4 2019 year
One of the main remaining problems in the multi-threaded programs development is the organization of asynchronous data access from different threads. The usage of locking objects is the standard method of synchronizing data access from different threads. Ensuring sequential access to shared data, locks reduces the degree of parallelism and decreases the overall performance of parallel algorithms. To reduce the number of locks, it is preferable to use a separate copy of the data for each running thread. The article discusses the method of dynamic allocation of memory associated with a specific thread. Thus, each executed thread has its own copy of the data and the need for synchronization disappears. The discussed method is implemented in the form of a C++ class that ensures the storage of a pointer to the memory local to the current thread and subsequent access to it. Pointers to the allocated memory are stored in an associative array. The access key is the identifier of the current thread. At the thread termination it is required to free the allocated memory associated with this thread. Based on the use of C++ threadlocal qualifier, a special mechanism has been developed for freeing the memory associated with the thread when it is completed. An example of using the developed class in calculating the values of B-splines in a multithreaded environment is given. It is shown that the use of standard synchronization methods (stack variables, critical sections) when using auxiliary arrays in the B-spline calculation algorithm has significant overheads. The use of the developed method reduces the need for synchronization objects and improves the performance of calculating B-splines in multi-threaded programs.