Skip to content

Instantly share code, notes, and snippets.

@piaoapiao
Created August 13, 2012 08:45
Show Gist options
  • Save piaoapiao/3338367 to your computer and use it in GitHub Desktop.
Save piaoapiao/3338367 to your computer and use it in GitHub Desktop.
不错心得
-(void)add:(NSString *)data
{
[theLock lock];
NSLog(@"%@%d",data,ticketNumber);
ticketNumber--;
[theLock unlock];
}
- (void)viewDidLoad
{
NSString *stackOverUrl = @"http://stackoverflow.com";
ASIHTTPRequest *request2 = [[ASIHTTPRequest alloc] initWithURL:[[NSURL alloc]initWithString:stackOverUrl
]];
request2.tag = 2;
request2.delegate = self;
[request2 startAsynchronous];
NSString *baiduUrl = @"http://www.baidu.com";
for(int i = 0;i<100;i++)
{
ASIHTTPRequest *request1 = [[ASIHTTPRequest alloc] initWithURL:[[NSURL alloc]initWithString:baiduUrl ]];
request1.delegate = self;
request1.tag = i;
[request1 startAsynchronous];
}
ticketNumber = 100;
theLock = [[NSLock alloc] init];
for(int i = 0;i<100;i++)
{
NSString *data = [NSString stringWithFormat:@"thread%d:",i];
[NSThread detachNewThreadSelector:@selector(add:) toTarget:self withObject:data];
}
}
-(void)requestFinished:(ASIHTTPRequest *)request
{
NSLog(@"request:%d",request.tag);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment