I think you forgot to protect access in the getter.
get {
queue.sync { unsafeState }
}
Likewise you should not use unsafeState
in your notify code, but rather send(self.state)
or send(newValue)
.
But note that the whole concurrent barrier queue is a known anti-pattern (see this post by David Smith). You'd be better off simply using a lock.