#define PTHREAD_CREATE(thread, attr,start_routine, arg) pthread_create(thread, attr,start_routine, arg)
#define PTHREAD_SETNAME_NP(thread, name) pthread_setname_np(thread, name)
#define PTHREAD_JOIN(thread, retval) pthread_join(thread, retval)
#define PTHREAD_EXIT(retval) pthread_exit(retval)
typedef pthread_t PTHREAD_T;
static PTHREAD_T P_RearSensorDetectThread = 0;
static BOOL P_RearSensorDetectExit;
void* P_RearSensor_Detection_Func(void *argv)
{
while (!P_SensorDetectExit)
{
//usleep(200*1000*1);
//sleep(1);
usleep(300000);
}
printf("[SM] P_RearSensor_Detection_Func: pthread_exit\n");
PTHREAD_EXIT(NULL);//task_exit:
return NULL;
}
void P_RearSensor_StartThread(void)
{
int ret = 0;
P_RearSensorDetectExit = FALSE;
if (0 != P_RearSensorDetectThread){
printf("P_RearSensorDetectThread alread start\n");
return;
}
ret = PTHREAD_CREATE(&P_RearSensorDetectThread, NULL, P_RearSensor_Detection_Func, NULL);
if (0 == ret)
PTHREAD_SETNAME_NP(P_RearSensorDetectThread, "Rearsensor_task");
else
printf("P_RearSensor_StartThread pthread_create failed\n");
return;
}
void P_RearSensor_StopThread(void)
{
P_RearSensorDetectExit = TRUE;
if (0 != P_RearSensorDetectThread)
{
PTHREAD_JOIN(P_RearSensorDetectThread, NULL);
P_RearSensorDetectThread = 0;
}
return;
}
Linux |线程编程实例1
于 2024-08-01 19:29:47 首次发布