其他分享
首页 > 其他分享> > c-为什么solaris 10中的SIGEV_THREAD的timer_create抛出错误?

c-为什么solaris 10中的SIGEV_THREAD的timer_create抛出错误?

作者:互联网

我通过使用timer_create设置计时器来调用一个线程,在其中我将sigev_notify设置为SIGEV_THREAD,它给我错误EINVAL(Invalid parameter),但是当我将sigev_notify设置为SIGEV_SIGNAL代码时,工作正常.

我的这段代码即使在solaris 11中也可以在所有操作系统中使用,但是对于solaris 10,却给我错误.

下面给出的代码:

{
int status =0;
struct itimerspec ts;
struct sigevent se;

se.sigev_notify = SIGEV_THREAD;
se.sigev_value.sival_int = val;
se.sigev_notify_function = func;
se.sigev_notify_attributes = NULL;

status = timer_create(CLOCK_REALTIME, &se, timer_id);

ts.it_value.tv_sec = abs(delay);
ts.it_value.tv_nsec = (delay-abs(delay)) * 1e09;
ts.it_interval.tv_sec = abs(interval);
ts.it_interval.tv_nsec = (interval-abs(interval)) * 1e09;

status = timer_settime(*timer_id, 0, &ts, 0);

}

请帮我解决这个问题.

提前致谢…

解决方法:

根据this man-page,Solaris 10不知道SIGEV_THREAD,而仅

The sigev_notify member specifies the notification mechanism to use when an asynchronous event occurs. The sigev_notify member may be defined with the following values:

SIGEV_NONE

No asynchronous notification is delivered when the event of interest occurs.

SIGEV_SIGNAL

A queued signal, with its value application-defined, is generated when the event of interest occurs.

SIGEV_PORT

An asynchronous notification is delivered to an event port when the event of interest occurs. The sival_ptr member points to a port_notify_t structure (see port_associate(3C)). The event port identifier as well as an application-defined cookie are part of the port_notify_t structure

标签:c-3,c,timer,signals,solaris-10
来源: https://codeday.me/bug/20191013/1909308.html