Grand centraldispatch

1,490 views

Published on

東京iPhone勉強会 #6 発表資料

Published in: Technology
0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,490
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
12
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Grand centraldispatch

    1. 1. 2
    2. 2. 3
    3. 3. 4
    4. 4. 5
    5. 5. 6
    6. 6. 7
    7. 7. 8
    8. 8. 9
    9. 9. 10
    10. 10. 12
    11. 11. 13
    12. 12. 14
    13. 13. 15
    14. 14. 16
    15. 15. 17
    16. 16. 18
    17. 17. 19
    18. 18. 21
    19. 19. 22
    20. 20. 23
    21. 21. 24
    22. 22. n = IO.read("count.txt") rescue "0"open("count.txt","w") {|f| f.puts n.to_i + 1} 26
    23. 23. n = IO.read("count.txt") rescue "0" n = IO.read("count.txt") rescue "0"open("count.txt","w") {|f| f.puts n.to_i + 1} open("count.txt","w") {|f| f.puts n.to_i + 1} 27
    24. 24. n = IO.read("count.txt") rescue "0"open("count.txt","w") {|f| f.puts n.to_i + 1} 28
    25. 25. 29
    26. 26. 30
    27. 27. while (true) begin break if Dir.mkdir("lock.txt") rescue sleep(1) endendn = IO.read("count.txt") rescue "0"open("count.txt","w") {|f| f.puts n.to_i + 1}Dir.rmdir("lock.txt") 31
    28. 28. lock(“a”) lock(“b”)lock(“b”) lock(“a”)unlock(“b”) unlock(“a”)unlock(“a”) unlock(“b”) 32
    29. 29. 34
    30. 30. 35
    31. 31. 36
    32. 32. 37
    33. 33. - (void)countThread:(id)param{ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; [pool release];} [NSThread detachNewThreadSelector:@selector(countThread:) toTarget:self withObject:self]; NSLog(@"Thread started."); 38
    34. 34. 39
    35. 35. 40
    36. 36. - (int) maxOfArray:(int *)a count:(int)n { static int max = 0; for (int i = 0; i < n; i++) { if (a[i] > max) max = a[i]; } return max;} 41
    37. 37. - (int)randomNumber { static int rand = 7654321; rand = (rand * 12345 + 678901) & 0x7fff; return rand;} 42
    38. 38. 43
    39. 39. NSMutableDictionary *threadLoacl = [[NSTread currentThread] threadDictonary];[threadLocal setObject:@”Test” forKey:@”mode”];s = [threadLocal objectForKey:@”mode”] 44
    40. 40. @interface MyInt : NSObject { int intValue;}@end@implementation MyInt-(int) getInt { return intValue;}-(void) setOddInt:(int)i { intValue = i; intValue = (intValue >> 1) << 1;}@end 45
    41. 41. @interface MyString : NSObject { NSMutableString *str;}@end@implementation MyInt-(MyString *) getString { return str;}-(void) addString:(NSString *)s { [str appendString:s];}@end 46
    42. 42. 47
    43. 43. 48
    44. 44. @interface MyPoint : NSObject { GCPoint point;}@end@implementation MyInt-(GCPoint) getPoint { return point;}-(void) setPoint:(GCPoint)p { point = p;}@end 49
    45. 45. @interface MyString : NSObject { NSString *string;}@property (nonatomic, retain) NSString *string;@end@implementation MyString@synthesize string;@end 50
    46. 46. 51
    47. 47. 52
    48. 48. 54
    49. 49. 55
    50. 50. 57
    51. 51. 58
    52. 52. 59
    53. 53. @interface CountOperation : NSOperation { id delegate;}@implementation CountOperation- (id)initWithDelegate:(id)aDelegate { self = [super init]; if (self != nil) { delegate = aDelegate; } return self;}- (void)main { NSAutoreleasePool *pool = [NSAutoreleasePool new]; [pool release];}@end queue = [[NSOperationQueue alloc] init]; CountOperation *op = [[[CountOperation alloc] initWithDelegate:self] autorelease]; [queue addOperation:op]; NSLog(@"Thread started.");} 60
    54. 54. 62
    55. 55. 63
    56. 56. {|ary| ^(NSArray *ary) { s = “” NSMutableString *s = [NSMutableString string]; for a in ary for (NSString *a in ary) { s += a [s appendString:a]; end } s return s;} } 64
    57. 57. __block NSMutableString *s = [NSMutableString string];^(NSArray *ary) { for (NSString *a in ary) { [s appendString:a]; }} 65
    58. 58. - (NSArray *)sortedArrayUsingSelector:(SEL)comparator- (NSArray *)sortedArrayUsingComparator:(NSComparator)cmptr 66
    59. 59. 67
    60. 60. 68
    61. 61. 70
    62. 62. 72

    ×