C variable metrics - __declspec (thread)

I am working on a multi-threaded implementation of a library. In one module of this library there are several global variables (very often used when executing a program). To make access to these variables more secure, I announced that they use the __declspec(thread)local storage (TLS) keyword .

Here is the call to the external library function. This function uses a module with global variables:

for(i = 0; i<n_cores; i++)
    hth[i] = (HANDLE)_beginthread((void(*)(void*))MT_Interface_DimenMultiCells,0,(void*)&inputSet[i]);

Thus, I think that all the variables used in the library will be duplicated for each thread.

When I run the program on the x8 kernel processor, the time required to complete the operation does not exceed 1/3 of the time required to implement one process.

I know that it’s impossible to reach 1/8 of the time, but I thought that at least 1/6 could be found.

The question is, are these __declspec (thread) variables causing such bad actions?

Thanks in advance, GB

+3
source share
2 answers

If you declare them as __declspec(thread)where they were previously global, then you have changed the value of the program, as well as its performance.

When the variable was global, there was a single copy referenced by each thread. Like a local thread, each individual thread has its own variable, and changes to this local thread variable are visible only in that thread.

, , , , , . , , , . :

  • , . .
  • , , ( ), , , .

. 2 , , , .

1 , ( - ).

, , , , . , , , , .

+5

: , . , TLS, "" .

, , : , , .

, .

+4

Source: https://habr.com/ru/post/1793823/


All Articles