IF we use custom concurrent queue to resolve this issue why we use dispatch_sync for reading and dispatch_async with barrier for writing?
Can't we use dispatch_async for reading as well ?
What is the difference here?
IF we use custom concurrent queue to resolve this issue why we use dispatch_sync for reading and dispatch_async with barrier for writing?
Can't we use dispatch_async for reading as well ?
What is the difference here?
Can't we use dispatch_async for reading as well ?
No, dispatch_async
says “dispatch this block of code to run asynchronously, but don’t wait for it to finish”. But the purpose of the “reader” is to provide thread-safe access to the value and return that value. If you use dispatch_async
, you may return back from your “reader” method before the dispatch_async
block has a chance to run.