2003-06-24 03:46:13 +00:00
|
|
|
#include <Foundation/Foundation.h>
|
2002-11-03 15:52:54 +00:00
|
|
|
|
2003-07-20 06:37:25 +00:00
|
|
|
NSLock *lock = nil;
|
|
|
|
|
2002-11-03 15:52:54 +00:00
|
|
|
@interface XX : NSObject
|
|
|
|
- (void) fire;
|
|
|
|
- (void) setup;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation XX
|
|
|
|
- (void) fire
|
|
|
|
{
|
|
|
|
NSLog(@"Got here");
|
|
|
|
}
|
|
|
|
- (void) setup
|
|
|
|
{
|
|
|
|
CREATE_AUTORELEASE_POOL(arp);
|
|
|
|
|
2003-07-20 06:37:25 +00:00
|
|
|
NSLog(@"Attempting to obtain lock to proceed");
|
|
|
|
if ([lock lockBeforeDate: [NSDate dateWithTimeIntervalSinceNow: 5.0]] == YES)
|
|
|
|
{
|
|
|
|
NSLog(@"Setup1");
|
|
|
|
[NSThread sleepUntilDate: [NSDate dateWithTimeIntervalSinceNow: 1.0]];
|
|
|
|
NSLog(@"Setup2");
|
|
|
|
[self performSelectorOnMainThread: @selector(fire)
|
|
|
|
withObject: nil
|
|
|
|
waitUntilDone: NO];
|
|
|
|
NSLog(@"Done perform no wait.");
|
|
|
|
[NSThread sleepUntilDate: [NSDate dateWithTimeIntervalSinceNow: 1.0]];
|
|
|
|
NSLog(@"Setup3");
|
|
|
|
[self performSelectorOnMainThread: @selector(fire)
|
|
|
|
withObject: nil
|
|
|
|
waitUntilDone: YES];
|
|
|
|
NSLog(@"Done perform with wait.");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NSLog(@"Failed to obtain lock");
|
|
|
|
}
|
2002-11-03 15:52:54 +00:00
|
|
|
RELEASE(arp);
|
|
|
|
[NSThread exit];
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
int main(int argc, char **argv, char **env)
|
|
|
|
{
|
2003-07-20 06:37:25 +00:00
|
|
|
CREATE_AUTORELEASE_POOL(arp);
|
2005-02-22 11:22:44 +00:00
|
|
|
|
2002-11-03 15:52:54 +00:00
|
|
|
NSLog(@"Start in main");
|
2003-07-20 06:37:25 +00:00
|
|
|
lock = [NSLock new];
|
|
|
|
[lock lock];
|
|
|
|
|
2002-11-03 15:52:54 +00:00
|
|
|
[NSThread detachNewThreadSelector: @selector(setup)
|
|
|
|
toTarget: [XX new]
|
|
|
|
withObject: nil];
|
2003-07-20 06:37:25 +00:00
|
|
|
NSLog(@"Waiting to give thread time to start");
|
|
|
|
[NSThread sleepUntilDate: [NSDate dateWithTimeIntervalSinceNow: 1.0]];
|
|
|
|
NSLog(@"Releasing lock so thread may proceed");
|
|
|
|
[lock unlock]; // Allow other thread to proceed.
|
|
|
|
|
2002-11-03 15:52:54 +00:00
|
|
|
[[NSRunLoop currentRunLoop] runUntilDate:
|
|
|
|
[NSDate dateWithTimeIntervalSinceNow: 10.0]];
|
2005-02-22 11:22:44 +00:00
|
|
|
|
2002-11-03 15:52:54 +00:00
|
|
|
NSLog(@"Done main thread");
|
2003-07-20 06:37:25 +00:00
|
|
|
|
|
|
|
DESTROY(arp);
|
2002-11-03 15:52:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|