【发布时间】:2022-11-11 18:12:29
【问题描述】:
我的问题如下:
如果过了一定时间,有没有办法继续我的代码并跳过输入
例如 :
printf("How old are you");
int age;
scanf("%d",&age);
// I don't know how to check if the time has been exeeded
sleep(5)
if("Time exeeded"){
printf("It's seems like the user is not there\n\n Goodbye");
return 1;
}
else {
printf("You are %d",age);
return 0;
}
谢谢您的回答
【问题讨论】:
-
您需要在这里运行两个不同的线程(这是使用
semaphores 的上下文)。 -
我必须把研究重点放在 sem_wait 和 sem_post 上吗?
-
你不能用标准 C 来解决这个问题。你需要一个不阻塞的输入函数。这将是特定于操作系统的。