I try to set a timer in a new created thread, but it’s not working when the timer set in the thread, my code is below:
[code]int main( )
{
int flag=1;
// Initialise I/O permitions to ISA card memory address
struct pci_dev_info info;
void *hdl;
int i,jj;
char F;
pthread_attr_t attr; //thread
pthread_attr_init( &attr );
pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_DETACHED );
pthread_create( NULL, &attr, &sockthread, NULL );
}
void* sockthread( )
{
int i;
//========================timer setup20100623
struct sigevent event;
struct itimerspec itime;
timer_t timer_id;
int chid;
int rcvid;
my_message_t msg;
int conid;
//===================================timer setup 20100623
//=============below set timer 20100623
chid = ChannelCreate(0);
conid=ConnectAttach(ND_LOCAL_NODE, 0, chid, _NTO_SIDE_CHANNEL, 0)ï¼›
event.sigev_notify = SIGEV_PULSE;
event.sigev_coid = ConnectAttach(ND_LOCAL_NODE, 0,
chid,
_NTO_SIDE_CHANNEL, 0);
event.sigev_priority = getprio(0);
event.sigev_code = MY_PULSE_CODE;
timer_create(CLOCK_REALTIME, &event, &timer_id);
itime.it_value.tv_sec = 0;
// 500 million nsecs = .004 secs
itime.it_value.tv_nsec = 4000000;
itime.it_interval.tv_sec = 0;
// 500 million nsecs = .004 secs
itime.it_interval.tv_nsec = 4000000;
timer_settime(timer_id, 0, &itime, NULL);
//=============below set timer 20100623
for (;
{
rcvid = MsgReceive(chid, &msg, sizeof(msg), NULL);
if (rcvid ==0)
{
if(msg.pulse.code == MY_PULSE_CODE)
{
printf(“we got a pulse from our timer\n”);
}
}
}
[/code]
It is a simple test, butrcvid always go wrong,please help!!
THANKS A LOTS