+ (instancetype) sharedinstance{ static bookmanager *sharedinstance = nil; Static dispatch_once_t Oncetoken; Dispatch_once (&oncetoken, ^{ = [[Self alloc] init]; }); return sharedinstance;}
Reference: http://blog.csdn.net/sakulafly/article/details/34948689
void Dispatch_once (dispatch_once_t *predicate, dispatch_block_t block);
We can see that this function receives a dispatch_once_t parameter and a block parameter. For a given predicate, the function guarantees that the relevant block is bound to execute and executes only once, and most importantly-the method is fully thread-safe. It is important to note that for blocks that need to be executed only once, the incoming predicate must be identical, so predicate is often decorated with static or global.
The benefits of this writing are obvious: The code is simple and clear, and thread-safe. In addition, the dispatch_once is efficient and does not implement a heavy-weight synchronization mechanism, so the efficiency of the implementation is also high.
IOS single-piece notation singleton