Iphone 交替打印2个线程值
在我的两个线程中有两组值,例如,在我的第一个线程中有奇数,在第二个线程中有偶数,但我想打印像1,2,3,4这样的值……如何交替打印线程值Iphone 交替打印2个线程值,iphone,ios,multithreading,Iphone,Ios,Multithreading,在我的两个线程中有两组值,例如,在我的第一个线程中有奇数,在第二个线程中有偶数,但我想打印像1,2,3,4这样的值……如何交替打印线程值 NSThread* myThread = [[NSThread alloc] initWithTarget:self selector:@selector(myThreadMainMethod:) object:nil]; [myThread setThreadPriority:1]; NSThread* myThread2 = [[NSThread all
NSThread* myThread = [[NSThread alloc] initWithTarget:self selector:@selector(myThreadMainMethod:) object:nil];
[myThread setThreadPriority:1];
NSThread* myThread2 = [[NSThread alloc] initWithTarget:self selector:@selector(myThreadMainMethod2:) object:nil];
[myThread2 setThreadPriority:1];
[myThread start]; // Actually create the thread
[myThread2 start]; // Actually create the thread
谢谢。如果您想让线程按顺序输出(在您的情况下,这似乎是一个非常糟糕的主意),那么您必须将它们与事件同步,以便它们相互发出信号以执行序列中的下一步 然而,这会让你们失去所有在第一时间拥有线程的好处。如果您想打印一个有序的数字序列,只需在GUI线程上执行即可 对于在线程环境中进行的有意义的工作,您将进行拆分,以便尽可能少地依赖于任何其他线程所做的任何其他工作,从而实现真正的并行性
用线程做一些需要太多同步的事情,这样做的效果是它们必须连续运行,这是毫无意义的。谢谢Tony…非常感谢您的回复…将按照您的建议进行。。。