//非分离线程未使用join函数例子:
#include<stdlib.h>
#include<pthread.h>
#include<stdio.h>
#include<sched.h>
#include<errno.h>
void*consumer(void*p)
{
    static a=0 ;
    a++;
    printf("<<<<<<<<<<<<<<<<<<<<<(%u),%d\n",(unsigned)pthread_self(),a);
    pthread_exit(NULL);
}
int main(int argc,char*argv[])
{
    pthread_t t1,t2,t3 ;
    int ret ;
    do 
    {
        ret=pthread_create(&t1,NULL,consumer,NULL);
        if(ret!=0)
        {
            printf("create failed,%d\n",ret);
            exit(1);
        }
    }
    while(1);
    sleep(1);
    return 0 ;
}
/*创建350个左右的线程后,就不能再创建线程,已创建的线程线程号都不同。
<<<<<<<<<<<<<<<<<<<<<(33799056),362
<<<<<<<<<<<<<<<<<<<<<(25406352),363
<<<<<<<<<<<<<<<<<<<<<(17013648),364
<<<<<<<<<<<<<<<<<<<<<(8620944),365
create failed,12
非此程序输出,但可以说明问题*/

 

相关文章:

  • 2021-11-17
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-19
  • 2021-11-30
  • 2023-04-06
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-01-06
  • 2022-12-23
  • 2022-12-23
  • 2021-11-24
  • 2021-12-06
相关资源
相似解决方案