It's relatively unlikely that Swift's concurrency model, once it gains one,
will look all that similar to Objective-C's. For example*, if Swift were to
adopt a shared-nothing model where heap storage was per-thread and could only
be accessed by another thread by copying or moving the value to
Synchronization would indeed be an area of improvement for Swift. I would,
however, add that the primitive should also work with more than just functions.
For example, it should play nicely with closures and should most definitely
work with properties (to synchronize access for a given resource
I'd prefer to see block-scoped synchronization rather than whole-method-only;
it gives much more flexibility.
Note that you can use the objc synchronization feature with reference types:
// Or (_ obj:...) if you prefer the label-less objc style)
func synchronized(on obj: AnyObject, do block: ()
With a serial queue guarding the function or concurrent queues dumping into a
serial target queue, DispatchQueue.sync(execute:) can be used as a
synchronizing primitive suitable for most workflows. Have you tried exploring
libDispatch outside of Semaphores?
~Robert Widmann
> On Jun 12, 2017,
> On 12. Jun 2017, at 11:10, Erik Aigner via swift-evolution
> wrote:
>
> In my day to day tasks, synchronization primitives are used quite often. ObjC
> had the @synchronized attribute for methods. I didn’t find anything about
> this in swift evolution, so I
In my day to day tasks, synchronization primitives are used quite often. ObjC
had the @synchronized attribute for methods. I didn’t find anything about this
in swift evolution, so I thought i bring it up here. I think it would quite
easily be possible to introduce a synchronized qualifier for