-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNSTaskTest.m
79 lines (49 loc) · 1.98 KB
/
NSTaskTest.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//***************************************************************************
#include "NSTaskAdditions.h"
#include <assert.h>
//***************************************************************************
@interface Foo : NSObject
- (void)doIt;
@end
//---------------------------------------------------------------------------
static NSConditionLock* lock = nil;
@implementation Foo
- (void)doIt {
NSAutoreleasePool* topLevelPool = [[NSAutoreleasePool alloc] init];
static NSString* pathToTextile = @"/Users/andrep/Code/Skunkworks/"
@"RapidWeaver-Plugins/Markup-3.5/" @"MarkupFilters/Textile.pl";
// static char* const bytes = "h1. This is a textile test";
static NSData* testData = nil;
if (testData == nil)
testData = [[NSData
dataWithContentsOfFile:@"/Users/andrep/Desktop/Desktop Items/ET_Bitmap_BMP.cpp"] retain];
assert(testData != nil);
NSAutoreleasePool* subPool = [[NSAutoreleasePool alloc] init];
NSData* data =
[NSTask launchedTaskWithLaunchPath:pathToTextile arguments:nil standardInput:testData];
#if 0
NSLog(@"Got data (%lu): %@",
(unsigned long)[data length],
[NSString stringWithCString:static_cast<const char*>([data bytes]) length:[data length]]);
#endif
[subPool release];
[topLevelPool release];
[lock unlockWithCondition:YES];
}
@end
//---------------------------------------------------------------------------
NSInteger main(const NSInteger argc, const char* const argv[]) {
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
lock = [[NSConditionLock alloc] init];
for (NSInteger i = 0; i < 10000; i++) {
Foo* foo = [[Foo alloc] init];
[lock lockWhenCondition:NO];
[NSThread detachNewThreadSelector:@selector(doIt) toTarget:foo withObject:nil];
[lock lockWhenCondition:YES];
[lock unlockWithCondition:NO];
[foo release];
NSLog(@"At iteration %ld", (long)i);
}
[pool release];
}
//***************************************************************************