Safely locking variable in Swift 3 using GCD

Viewed 5024

How to lock variable and prevent from different thread changing it at the same time, which leads to error?

I tried using

func lock(obj: AnyObject, blk:() -> ()) {
     objc_sync_enter(obj)
     blk()
     objc_sync_exit(obj)
}

but i still have multithreading issues.

2 Answers
Related