viraptor
viraptor

Reputation: 34145

STM hash library for C (glib?)

I'm looking for some C library that includes STM-style (Software Transactional Memory) hash maps, but I had no luck so far. It would be great if it was based on glib / gobject, but it's not that crucial. It also doesn't need proper transactions over many objects - single immutable hash support is all I really need.

Must haves: immutable snapshot read, lock-free write with auto-retry.

Upvotes: 6

Views: 1382

Answers (3)

hack99
hack99

Reputation: 1

TBoost.STM has implemented a hash map in its example.

Upvotes: 0

minjang
minjang

Reputation: 9050

Well, I think (and there are a number of study) that current STM isn't faster than lock-free and mutex-based code. It is obvious: STM requires on-line data conflict checking. However, such conflict checking in pure software requires very huge time overheads. Currently, only Sun's ROCK processor supports a limited form of STM (Best-effort HTM with STM) by hardware. No x86 CPUs currently support TM in hardware. In short, STM is just slow.

In my opinion, you'd better just using a concurrent hash table. For example, you can find concurrent_hash_map in Intel TBB. Here is the link of TBB Manual. Oh, but it's C++, not C. But, I do believe you can (though it might take significant work) translate C++-based such hash table to C code. Intel TBB is open source.

Also, I think such highly concurrent (usually implemented as lock-free) data structures are not always useful. In some workload pattern, using such data structures is not good. To be sure, I recommend you to write a small micro-benchmark for two versions of hash tables: (1) lock-free and (2) lock-based. Also, please keep in mind the workload patterns for such micro-benchmark should be close to real one. An example could be found in here.

Upvotes: 3

R Samuel Klatchko
R Samuel Klatchko

Reputation: 76541

Wikipedia has a list of various STM implementations.

Upvotes: 4

Related Questions