Subj : Re: nptl and signals To : comp.programming.threads From : Christian Parpart Date : Tue Aug 23 2005 10:01 am divijbhatt@gmail.com wrote: > Hi, > I want to know that how can I set the timer on a per thread basis in > POSIX threads (NPTL) Linux. to setup the timer, do: #include #include #include #include timer_t handle; struct sigevent ev; ev.sigev_value.sival_ptr = your.private.ptr; ev.sigev_signo = 0; ev.sigev_notify = SIGEV_THREAD; /* for threaded timer notification */ ev.sigev_notify_function = &timerNotify; ev.sigev_notify_attributes = 0; if (timer_create(CLOCK_REALTIME, &ev, &handle) != -1) { struct itimerspec it; /* first notify comes within 1 seconds */ it.it_value.tv_sec = 1; it.it_value.tv_nsec = 0; /* each further notify has the same timespan */ it.it_interval.tv_sec = it.it_value.tv_sec; it.it_interval.tv_nsec = it.it_value.tv_nsec; if (timer_settime(handle, 0, &it, 0) != -1) fprintf(stderr, "Timer initialized\n"); else fprintf(stderr, "timer_settime: %s\n", strerror(errno)); } else fprintf(stderr, "timer_create: %s\n", strerror(errno)); your timerNotify could look like: void timerNotify(sigval_t ASignalValue) { fprintf(stderr, "Blah!\n"); } to stop the timer, do: timer_delete(handle); handle = 0; .