小编rek*_*mso的帖子

NPTL最大线程为65528?

以下代码应该生成100,000个线程:

/* compile with:   gcc -lpthread -o thread-limit thread-limit.c */
/* originally from: http://www.volano.com/linuxnotes.html */

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <pthread.h>
#include <string.h>

#define MAX_THREADS 100000
int i;

void run(void) {
  sleep(60 * 60);
}

int main(int argc, char *argv[]) {
  int rc = 0;
  pthread_t thread[MAX_THREADS];
  printf("Creating threads ...\n");
  for (i = 0; i < MAX_THREADS && rc == 0; i++) {
    rc = pthread_create(&(thread[i]), NULL, (void *) &run, NULL);
    if (rc == 0) {
      pthread_detach(thread[i]);
      if …
Run Code Online (Sandbox Code Playgroud)

c linux multithreading pthreads nptl

5
推荐指数
1
解决办法
4505
查看次数

标签 统计

c ×1

linux ×1

multithreading ×1

nptl ×1

pthreads ×1