NSThread 售票员售票问题
来源:互联网 发布:奥迪宝马奔驰知乎 编辑:程序博客网 时间:2024/05/17 02:37
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ self.tickets = 20; NSThread *threadA = [[NSThread alloc] initWithTarget:self selector:@selector(saleTickets) object:nil]; threadA.name = @"售票员 A"; [threadA start]; NSThread *threadB = [[NSThread alloc] initWithTarget:self selector:@selector(saleTickets) object:nil]; threadB.name = @"售票员 B"; [threadB start];}- (void)saleTickets{ while (YES) { // 模拟休眠 [NSThread sleepForTimeInterval:1.0f]; //枷锁 防止资源抢夺错误 @synchronized(self) { if (self.tickets > 0) { self.tickets--; NSLog(@"剩余票数 %@ %d", [NSThread currentThread], self.tickets); } else { break; } } }}
0 0
- NSThread 售票员售票问题
- 售票员
- 售票问题
- java同步代码块问题(售票员)
- iOS 多线程实例(NSThread售票窗口的模拟)
- JAVA多线程售票问题
- CYC-多线程 售票问题
- Java多线程售票问题
- JAVA多线程售票问题
- JAVA多线程售票问题
- 进程间用信号通信(司机和售票员问题)
- PV操作解决公交车与售票员同步问题
- 进程间通信-信号(售票员、司机上下车问题)
- 同步互斥——司机售票员问题
- 多线程解决窗口售票问题
- java线程关于售票问题
- 队列应用之售票窗口问题_legend
- Java 多线程之多个窗口售票问题
- 黑马程序员JAVA笔记9--反射
- c#实现统计代码执行时间
- 【BZOJ2823】【AHOI2012】信号塔 最小圆覆盖 计算几何
- Linux ALSA声卡驱动之六:ASoC架构中的Machine
- mysql too many connections解决
- NSThread 售票员售票问题
- 一行代码给网站添加功能
- 【swift_4】swift之代理传值(delegate的用法)
- 获取当前系统版本
- IIS建立FTP站点
- 最近流行的QQ爱情说说:爱情可以让人忘了时间
- UVa 10739 - String to Palindrome
- Linux ALSA声卡驱动之七:ASoC架构中的Codec
- 设计模式学习之装饰模式:IO流的装饰器