我不是C开发人员,但我需要编写简单的程序,而且延迟也有问题。这是我的节目:
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <wiringPi.h>
#include <softPwm.h>
int main (int argc, char *argv[])
{
int val = 10;
if (argc > 1) {
val = atoi(argv[1]);
}
wiringPiSetup () ;
pinMode(1, OUTPUT);
softPwmCreate (1, 0, 100) ;
printf ("Soft Pwm created: %s!\n", argv[1]) ;
softPwmWrite (1, val) ;
delay (200);
return 0;
}在我删除带有delay (200)的行之前,它运行得很好。在程序完成之前,我怎样才能等到函数softPwmWrite完成,而没有delay()呢?Im‘使用Linux和wiringPi库。谢谢。
发布于 2015-07-16 07:32:59
包括pthread.h和调用pthread_exit
#include <pthread.h>
....
softPwmWrite (1, val) ;
pthread_exit(0);
}当softPwmWrite返回时,它将退出程序。softPwmWrite使用线程,您只需要确保程序不会在线程完成之前就死掉。当所有线程完成时,进程将在结束时退出。
https://stackoverflow.com/questions/31447841
复制相似问题