Transaction Memory
is a concurrency mechanism, which provides atomic and isolated compared with normal memory access. Transaction memory
is easy to use, and simplify concurrent programming without lock or extra concurrent control method.
C++20 implements Transaction Memory
, and makes this becomes a standard in C++. I think this is the inevitable trend with rapid development in multi-core programming.
In gcc-7
, programmer can use more than three ways to use Transaction Memory
, and I will introduce how to write codes by taking advantage of Transaction Memory
Below is a example with using synchronized
keyword to achieve synchronized of multi threads.
|
|
The output in screen is like that:
Only one thread can access this variable i
at any time.