English 中文(简体)
为什么我拿到“error:`pthread_delay_np'这个范围没有申报”?
原标题:Why do I get "error: ‘pthread_delay_np’ was not declared in this scope"?

我正试图看到,能否避免一线read子在read子之后立即开始。 因此,我走过了read子,我尝试了:

#define _MULTI_THREADED
#include <stdio.h>
#include <time.h>
#include <pthread.h>
#define NTHREADS 5

void *threadfunc(void *parm)
{
  int               rc;
  struct timespec   ts = {0, 0};

  /* 5 and 1/2 seconds */
  ts.tv_sec  = 5;
  ts.tv_nsec = 500000000;

  printf("Thread blocked
");
  rc = pthread_delay_np(&ts);
  if (rc != 0) {
    printf("pthread_delay_np() - return code %d
", rc);
    return (void*)&rc;
  }
  printf("Wait timed out!
");

  return NULL;
}

int main(int argc, char **argv)
{
  int                   rc=0;
  int                   i;
  pthread_t             threadid[NTHREADS];
  void                 *status;
  int                   fail=0;

  printf("Enter Testcase - %s
", argv[0]);

  printf("Create %d threads
", NTHREADS);
  for(i=0; i<NTHREADS; ++i) {
    rc = pthread_create(&threadid[i], NULL, threadfunc, NULL);
  }

  printf("Wait for threads and cleanup
");
  for (i=0; i<NTHREADS; ++i) {
    rc = pthread_join(threadid[i], &status);
    if (status != NULL) {
      fail = 1;
    }
  }

  if (fail) {
    printf("At least one thread failed!
");
    return 1;
  }
  printf("Main completed
");
  return 0;
}

但是,我保留了“error:`pthread_delay_np'这个范围没有宣布”。 没有人知道为什么?

此外,还没有任何其他办法防止透镜在read后立即开始? 是否与时间表有关?

advance!

问题回答

Quoting from 部分邮寄名单:

也可在HP-UX、VMS和Tru64 UNIX上查阅。 <代码>pthread_delay_np(>起源于POSIX.1c标准D4草案。 POSIX.1c D4的主要实施者是分布式电子环境处。 斜体表示,APIC是不可运输的,不能依赖另一个平台。 一般而言,nanosleep()是你希望用作替代物。

Just use nanosleep(2).

看来,<代码>pthread_delay_np是一种非标准、不可运输的(hence the "_np” suffix)功能。 你们的平台是否存在?

你们可以用ema光向read子表示,它可以开始执行ema光等点。

答案可能取决于你试图通过避免read子的立即开始来实现的目标。

http://www.ohchr.org。

然而,我确信,固定的拖延是而不是你实际需要的东西,除非你与环境(例如硬件)或只是进行试验。





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签