其他分享
首页 > 其他分享> > NSThread和fork

NSThread和fork

作者:互联网

[NSThread detachNewThreadWithBlock:^{
        pid_t p1 = fork();
        pid_t p2 = fork();
        NSLog(@"当前线程%@  1:%d",[NSThread currentThread],p1);
        NSLog(@"当前线程%@  2:%d",[NSThread currentThread],p2);
    }];
NSThread *t = [[NSThread alloc] initWithBlock:^{
        pid_t p1 = fork();
        pid_t p2 = fork();
        NSLog(@"当前线程%@  1:%d",[NSThread currentThread],p1);
        NSLog(@"当前线程%@  2:%d",[NSThread currentThread],p2);
    }];
    NSLog(@"创建的线程 %@ %@",t,[NSThread currentThread]);
    [t start];

上下两个结果输出完全不一样,下面的线程居然都是一样的地址???并且有一堆警告信息⚠️

 

 

 

 

 

 

 

标签:fork,currentThread,NSLog,pid,线程,NSThread
来源: https://www.cnblogs.com/yuxiaoyiyou/p/13794642.html