Machx / Konkyo

A Foundation Swift Package for my projects

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Swift Atomic Compare and Swap func

Machx opened this issue · comments

// roughly equivalent to
// lock.lock()
// if shouldDoThing == true {
//     shouldDoThing = false
//     print(shouldDoThing)
// }
// lock.unlock
if AtomicCompareAndSwap(shouldDoThing, expecting: true, replaceWith: false) { 
    print(shouldDoThing) // false
}

This suffers from the problem of not knowing how to lock a specific thing and that thing only. It's almost like we'd have to make an extension on any and make a lock var for each variable somehow.

I am going to close this in this repository and instead move this issue to a more experimental repository where this concept can be explored until it is mature.