zoukankan      html  css  js  c++  java
  • 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];

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

  • 相关阅读:
    转载的,讲解java.util的集合类
    LinkedList
    数据结构
    随笔
    spring boot初步尝试
    spring boot
    java8 新特性
    volatile 续
    java 线程基础学习
    java 基础
  • 原文地址:https://www.cnblogs.com/yuxiaoyiyou/p/13794642.html
Copyright © 2011-2022 走看看