Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>For those that want a sample test class here I post what I did to play around and understand how NSCondition works.</p> <pre><code>// --- MyTestClass.h File --- // @interface MyTestClass - (void)startTest; @end // --- MyTestClass.m File --- // @implementation MyTestClass { NSCondition *_myCondition; BOOL _someCheckIsTrue; } - (id)init { self = [super init]; if (self) { _someCheckIsTrue = NO; _myCondition = [[NSCondition alloc] init]; } return self; } #pragma mark Public Methods - (void)startTest { [self performSelectorInBackground:@selector(_method1) withObject:nil]; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ sleep(5); [self performSelectorInBackground:@selector(_method2) withObject:nil]; }); } #pragma mark Private Methods - (void)_method1 { NSLog(@"STARTING METHOD 1"); NSLog(@"WILL LOCK METHOD 1"); [_myCondition lock]; NSLog(@"DID LOCK METHOD 1"); while (!_someCheckIsTrue) { NSLog(@"WILL WAIT METHOD 1"); [_myCondition wait]; NSLog(@"DID WAIT METHOD 1"); } NSLog(@"WILL UNLOCK METHOD 1"); [_myCondition unlock]; NSLog(@"DID UNLOCK METHOD 1"); NSLog(@"ENDING METHOD 1"); } - (void)_method2 { NSLog(@"STARTING METHOD 2"); NSLog(@"WILL LOCK METHOD 2"); [_myCondition lock]; NSLog(@"DID LOCK METHOD 2"); _someCheckIsTrue = YES; NSLog(@"WILL SIGNAL METHOD 2"); [_myCondition signal]; NSLog(@"DID SIGNAL METHOD 2"); NSLog(@"WILL UNLOCK METHOD 2"); [_myCondition unlock]; NSLog(@"DID UNLOCK METHOD 2"); } @end // --- Output --- // /* 2012-11-14 11:01:21.416 MyApp[8375:3907] STARTING METHOD 1 2012-11-14 11:01:21.418 MyApp[8375:3907] WILL LOCK METHOD 1 2012-11-14 11:01:21.419 MyApp[8375:3907] DID LOCK METHOD 1 2012-11-14 11:01:21.421 MyApp[8375:3907] WILL WAIT METHOD 1 2012-11-14 11:01:26.418 MyApp[8375:4807] STARTING METHOD 2 2012-11-14 11:01:26.419 MyApp[8375:4807] WILL LOCK METHOD 2 2012-11-14 11:01:26.419 MyApp[8375:4807] DID LOCK METHOD 2 2012-11-14 11:01:26.420 MyApp[8375:4807] WILL SIGNAL METHOD 2 2012-11-14 11:01:26.420 MyApp[8375:4807] DID SIGNAL METHOD 2 2012-11-14 11:01:26.421 MyApp[8375:4807] WILL UNLOCK METHOD 2 2012-11-14 11:01:26.421 MyApp[8375:3907] DID WAIT METHOD 1 2012-11-14 11:01:26.421 MyApp[8375:4807] DID UNLOCK METHOD 2 2012-11-14 11:01:26.422 MyApp[8375:3907] WILL UNLOCK METHOD 1 2012-11-14 11:01:26.423 MyApp[8375:3907] DID UNLOCK METHOD 1 2012-11-14 11:01:26.423 MyApp[8375:3907] ENDING METHOD 1 */ </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload