diff -r 000000000000 -r deb0ee0c5b21 Coroutines/MYCoroutineTest.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Coroutines/MYCoroutineTest.m Tue Apr 29 17:05:32 2008 -0700 @@ -0,0 +1,88 @@ +// +// MYCoroutineTest.m +// Coroutines +// +// Created by Jens Alfke on 4/29/08. +// Copyright 2008 __MyCompanyName__. All rights reserved. +// + +#import "MYCoroutine.h" + + +@interface CoroTest1 : MYCoroutine +{ + int value; +} +@property int value; +@end + +@interface CoroTest2 : CoroTest1 +@end + + +CoroTest1 *firstCoro, *secondCoro; + + +@implementation CoroTest2 + +- (void) main +{ + int num = 0; + + NSLog(@"secondTask created with value %d", self.value); + + while (1) + { + NSLog(@"secondTask: %d %d", self.bytesLeftOnStack, num++); + [firstCoro resume]; + } +} + +@end + + +@implementation CoroTest1 + +@synthesize value; + +- (void) main +{ + int num = 0; + + NSLog(@"firstTask created with value %d", self.value); + secondCoro = [[CoroTest2 alloc] init]; + secondCoro.name = @"second"; + secondCoro.value = 2; + [secondCoro start]; + + while ( num < 100 ) + { + NSLog(@"firstTask: %d %d", self.bytesLeftOnStack, num++); + [secondCoro resume]; + } + + [secondCoro release]; + + [[MYCoroutine mainCoroutine] resume]; +} + +@end + + +int main() +{ + NSAutoreleasePool *pool = [NSAutoreleasePool new]; + + NSLog(@"Starting test..."); + //[[[NSThread alloc] init] start]; + firstCoro = [[CoroTest1 alloc] init]; + firstCoro.name = @"first"; + firstCoro.value = 1; + [firstCoro start]; + + NSLog(@"Returned from coroutines; exiting"); + + [firstCoro release]; + + [pool drain]; +}