Created
August 13, 2012 08:45
-
-
Save piaoapiao/3338367 to your computer and use it in GitHub Desktop.
不错心得
This file contains hidden or 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
-(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