How dispatch_once runs only once?



How dispatch_once runs only once?..

Answer / Mrinal Kaushick

dispatch_once is a function provided by Apple's Grand Central Dispatch (GCD) library in Objective-C. It ensures that a block of code is executed no more than once during the lifetime of a particular process. This is achieved through an atomic flag, which prevents multiple threads from executing the block concurrently. The first time the function dispatch_once() is called for a specific control variable, the associated block will be executed. Subsequent calls to dispatch_once() with the same control variable will not execute the block again.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Objective-C Interview Questions

What is class extension?

1 Answers  


What is extern objective c?

1 Answers  


What does it mean to be objective?

1 Answers  


Does a thread created using performselectorinbackground:withobject: creates its own autorelease pool?

1 Answers  


What is the difference between weak and unowned?

1 Answers  


What is lazy var?

1 Answers  


What does __ block do?

1 Answers  


What happen if we send any message to an object which is released?

1 Answers  


What is assign property in objective c?

1 Answers  


Does objective-c contain private strategies?

1 Answers  


What is responder chain?

1 Answers  


What is thread safe function?

1 Answers  


Categories