title: Avoid Data Race condition in swift
body: <p>I am getting race conditions in my code when I run TSan tool. As same code has been accessed from different queues and threads at the same time that's why I can not use Serial queues or barrier as Queue will block only single queues accessing the shared resource not the other queues.</p>
  
  <p>I used <code>objc_sync_enter(object) | objc_sync_exit(object)</code> and locks <code>NSLock() or NSRecursiveLock()</code> to protect shared resource but these are also not working.</p>
  
  <p>While when I use <code>@synchronized()</code> keyword in Objective C to protect shared resource, it's working fine as expected and I am not getting race conditions in particular block of code.</p>
  
  <p>So, what is an alternative to protect data in Swift as we can not use <code>@synchronized()</code> keyword in Swift language.</p>
  
  <p>PFA screenshot for reference -
  <a href="https://i.stack.imgur.com/8KRcO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8KRcO.png" alt="Data Race"></a></p>