Well, I think (and there are some studies) that the current STM is not faster than the lock and mutex code. This is obvious: STM requires online data verification. However, such conflict checking in pure software is very time-consuming. Currently, only the Sun ROCK processor supports the limited form of STM (Best-effort HTM with STM) through hardware. No x86 processors currently support TM in hardware. In short, STM is slow.
In my opinion, you'd better just use a parallel hash table. For example, you can find concurrent_hash_map in Intel TBB. Here is the TBB Guide link. Oh, but this is C ++, not C. But I suppose you can (although it can take a lot of work) translate such a hash table from C ++ to C code. Intel TBB is open source.
In addition, I think that such highly competitive (usually implemented as blocking) data structures are not always useful. In some workload templates, the use of such data structures is not good. Of course, I recommend you write a small micro-test for two versions of the hash tables: (1) without blocking and (2) blocking. Also, remember that workload patterns for such a micro benchmark should be close to real. An example can be found in here .
minjang
source share