私のプログラムは単純な呼び出しでスタックしますusleep(1.);
。それはどうしてですか?何に気をつければいいですか?
編集:
事態をさらに混乱させるために、前に rand() を呼び出した場合にのみスタックします。
rand();
usleep(1.);
両方の呼び出しは個別に問題ありません。
編集2:
動作する最小限の例を次に示します。
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(int argc, char* argv[]) {
printf("Calling rand() and then usleep(1) on pid %d \n",getpid());
rand();
usleep(1);
printf("Finished.\n");
return 0;
}
これも機能します:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(int argc, char* argv[]) {
printf("Calling usleep(1.) on pid %d \n",getpid());
usleep(1.);
printf("Finished.\n");
return 0;
}
ただし、これは次のことを行いません。
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(int argc, char* argv[]) {
printf("Calling rand() and then usleep(1.) on pid %d \n",getpid());
rand();
usleep(1.);
printf("Finished.\n");
return 0;
}
コマンドを使用して、これらを gcc バージョン 4.4.6 でコンパイルしますgcc -std=c99 main.c
。オプション-std=c99
が問題?しかし、私はまだここで何が起こっているのか理解していません。