lockBeforeDate improvements.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@17263 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
CaS 2003-07-20 06:37:25 +00:00
parent b9bccee8c3
commit 7e4ef0cdc9
4 changed files with 208 additions and 101 deletions

View file

@ -1,5 +1,7 @@
#include <Foundation/Foundation.h>
NSLock *lock = nil;
@interface XX : NSObject
- (void) fire;
- (void) setup;
@ -14,19 +16,27 @@
{
CREATE_AUTORELEASE_POOL(arp);
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.");
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");
}
RELEASE(arp);
[NSThread exit];
}
@ -34,17 +44,26 @@
int main(int argc, char **argv, char **env)
{
id arp = [NSAutoreleasePool new];
CREATE_AUTORELEASE_POOL(arp);
NSLog(@"Start in main");
lock = [NSLock new];
[lock lock];
[NSThread detachNewThreadSelector: @selector(setup)
toTarget: [XX new]
withObject: nil];
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.
[[NSRunLoop currentRunLoop] runUntilDate:
[NSDate dateWithTimeIntervalSinceNow: 10.0]];
NSLog(@"Done main thread");
DESTROY(arp);
return 0;
}