首页 > 解决方案 > as400/IBM i 上的 pthread 错误代码 3025 (ENOENT)?

问题描述

当我有以下在 IBM i Midrange 上运行的 C 源代码时,我得到一个非零结果pthread_create,特别是 3025,它是 ENOENT(没有这样的路径或目录),这没有任何意义我。任何人都对错误在这种情况下 的实际含义有任何想法。

#define _MULTI_THREADED
#define _XOPEN_SOURCE 520
#include <pthread.h>
#include <stdio.h>
#include <errno.h>

void* workerThread(void* parm) {
    // Do some work here
    pthread_exit(NULL);
}

int main(int argc, char* argv[]) {
  pthread_t t;
  int rc;
  rc = pthread_create(&t, NULL, workerThread, NULL);
  if (rc != 0) {
    char *msg = strerror(errno);       
    perror("pthread_create failed");   
  }

  // Other code here

  return 0;
}

标签: pthreadsibm-midrange

解决方案


pthread_create没有设置errno。你应该检查 strerror. http://pubs.opengroup.org/onlinepubs/7908799/xsh/pthread_create.htmlrc

char *msg = strerror(rc);

推荐阅读