[size=1em]1 [size=1em]2 [size=1em]3 [size=1em]4 [size=1em]5 [size=1em]6 [size=1em]7 | [size=1em][size=1em]-(void)createProducer{ [size=1em] [condition lock]; [size=1em] [products addObject:[[NSObject alloc] init]]; [size=1em] NSLog(@”produce a product”); [size=1em] [condition signal]; [size=1em] [condition unlock]; [size=1em]} |
[size=1em]1 [size=1em]2 [size=1em]3 [size=1em]4 [size=1em]5 [size=1em]6 [size=1em]7 [size=1em]8 [size=1em]9 [size=1em]10 [size=1em]11 | [size=1em][size=1em]-(void)createConsumer{ [size=1em] [condition lock]; [size=1em] while ([products count]==0) { [size=1em] NSLog(@”wait for product”); [size=1em] [condition wait]; [size=1em] } [size=1em] [products removeObjectAtIndex:0]; [size=1em] NSLog(@”consume a product”); [size=1em] [condition unlock]; [size=1em]} |
ios学者 发表于 2015-12-7 18:29
先推荐你看一下操作系统的书其中 就有生产者,消费者的,先把逻辑搞清楚,代码是次要的,会点C就可以 ...
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |