Created
January 17, 2012 15:51
-
-
Save kiding/1627163 to your computer and use it in GitHub Desktop.
Sleep Sort - Objective-C (Cocoa)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
Version 2, December 2004 | |
Copyright (C) 2012 Dongsung "Don" Kim <[email protected]> | |
Everyone is permitted to copy and distribute verbatim or modified | |
copies of this license document, and changing it is allowed as long | |
as the name is changed. | |
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION | |
0. You just DO WHAT THE FUCK YOU WANT TO. | |
*/ | |
#import <Foundation/Foundation.h> | |
@interface SortControl : NSObject | |
- (void) sleepForTime:(id)param; | |
@end | |
@implementation SortControl | |
- (void) sleepForTime:(NSNumber *)param { | |
usleep([param intValue] * 1000000); | |
NSLog(@"%d", [param intValue]); | |
} | |
@end | |
int main (void) | |
{ | |
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; | |
int argv[9] = {1, 5, 7, 6, 2, 9, 8, 10, 13}; | |
int argc = 9; | |
SortControl *control = [[[SortControl alloc] init] autorelease]; | |
NSMutableArray *threads = [NSMutableArray array]; | |
for(int i=0; i<argc; i++) { | |
NSNumber *inputNumber = [NSNumber numberWithInt:argv[i]]; | |
NSInvocationOperation *thisThread = [[[NSInvocationOperation alloc] | |
initWithTarget:control | |
selector:@selector(sleepForTime:) | |
object:inputNumber] | |
autorelease]; | |
[threads addObject:thisThread]; | |
} | |
NSOperationQueue *queue = [[[NSOperationQueue alloc] init] autorelease]; | |
[queue addOperations:threads waitUntilFinished:YES]; | |
[pool drain]; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment