spion / hashtable-latencies

Latency of a web service that stores a large hashtable, in multiple languages
43 stars 8 forks source link

A question about multi-threading and thread safety #4

Closed kostya-sh closed 8 years ago

kostya-sh commented 8 years ago

This is not a bug report, just a question that I hope you can answer.

Comparing different versions of the applications I can see the following aproaches to avoid data races:

Go

Thank you.

spion commented 8 years ago

Swift is single-threaded yes. The language is multi-threaded but the Zewo runtime is based on libmill which is single-threaded.

Haskell is "safe-enough" that it doesn't crash.

MVar is a single-value channel which blocks on the next takeMVar until there is a new value in the channel (putMVar), so the increment is safe. Not sure about BasicHashTable, the mutation should probably be within the MVar lock.

edit: fixed, the hashtable mutation is now done within the lock.

kostya-sh commented 8 years ago

Thank you for the reply