devmynd/tabs — pull request #9 by DarthMax (2014-07-21 11:20:40+00:00)
Title: Fix race condition

There is a race condition in the following functions

- Tabs#increment_counter
- Tabs#record_value
- Tabs#start_task

All function check if the requested metric exist. If not they try to create it, but in the mean time it is possible that an other thread has already created it. This results in the following code to fail repeatedly with a `Tabs::DuplicateMetricError`

```ruby
5.times.map do
Thread.new do
Tabs.increment_counter("test_counter")
end
end.each(&:join)
```
Adding a get_or_create_metric function using a shared mutex prevents this race condition.