# Fixing the Silent Data Race

My skiplist.h code had a bug capable of causing data races at higher throughput.

Initially, when I ran my test harness with just two threads, each with one insert function, it compiled and ran successfully. I then increased the number to 10000 insertions per thread to see its performance, attempting to witness a potential hardware collision. And I did. It gave me a long output, the summary of which was:

```powershell
SUMMARY: ThreadSanitizer: data race src/skiplist.h:37 in SkipList<int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::Insert(int const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)
==================
ThreadSanitizer: reported 4 warnings
```

I checked line 37 and eventually understood what the problem was—candidate.value not being an atomic variable meant it was capable of being written to simultaneously by two distinct writing threads.

<mark class="bg-yellow-200 dark:bg-yellow-500/30">The fix is to make the value variable atomic.</mark>
