//
//  RandomThread.m
//  NSThreadExtension
//
//  Created by Jonathan Lung on 10/03/07.
//  Copyright 2007 __MyCompanyName__. All rights reserved.
//  http://www.cs.toronto.edu/~lungj

#import "RandomThread.h"


@implementation RandomThread
-(void) run:(id)anObject {
	int n = [(NSNumber*) anObject intValue];
	NSLog(@"Thread #%i", n);
	id foo = [NSAutoreleasePool alloc];
	NSAutoreleasePool* pool = [foo init];

	int sleepTime = ((float)rand() / INT_MAX) * 5 + 1;
	NSLog(@"Thread sleeping for %is", sleepTime);
	
	// Pretending to do some work...  just sleep instead.
	[NSThread sleepUntilDate:[[NSDate alloc] initWithTimeIntervalSinceNow:sleepTime]];
	
	NSLog(@"Thread slept for %is", sleepTime);
	
	[pool release];
}
@end
