How to Implement Semaphores in iOS Application?

前端 未结 4 423
长发绾君心
长发绾君心 2021-02-06 10:52

Is it possible to implement Counting Semaphore in ios application?

4条回答
  •  隐瞒了意图╮
    2021-02-06 11:50

    I was unable to find a native IOS object to do this but it works just fine using the C library:

    #import "dispatch/semaphore.h"
    ...
    dispatch_semaphore_t activity;
    ...
    activity = dispatch_semaphore_create(0);
    ...
    dispatch_semaphore_signal(activity);
    ...
    dispatch_semaphore_wait(activity, DISPATCH_TIME_FOREVER);
    

    Hope that helps.

提交回复
热议问题