Have you called thread_pool_create(), thread_pool_start()?
Here’s some real code:
-seanb
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <stddef.h>
#define THREAD_POOL_PARAM_T dispatch_context_t
#include <sys/dispatch.h>
const char *my_arg1=“Got one\n”;
const char *my_arg2=“Got two\n”;
int code1, code2, coid;
dispatch_t *dpp;
int pulse_input(message_context_t *ctp, int code, unsigned flags, void *handle);
void * worker (void *arg);
int
main(int argc, char **argv) {
thread_pool_attr_t pool_attr;
thread_pool_t *tpp;
timer_t tmr;
struct sigevent sig;
struct itimerspec to= {{1, 0}, {1, 0}};
if((dpp = dispatch_create()) == NULL)
{
fprintf(stderr, “%s: Unable to allocate dispatch context.\n”,argv[0]);
return EXIT_FAILURE;
}
memset(&pool_attr, 0, sizeof pool_attr);
pool_attr.handle = dpp;
pool_attr.context_alloc = dispatch_context_alloc;
pool_attr.block_func = dispatch_block;
pool_attr.handler_func = dispatch_handler;
pool_attr.context_free = dispatch_context_free;
pool_attr.lo_water = 1;
pool_attr.hi_water = 1;
pool_attr.increment = 0;
pool_attr.maximum = 1;
if((tpp = thread_pool_create(&pool_attr, POOL_FLAG_EXIT_SELF)) == NULL)
{
fprintf(stderr, “%s: Unable to initialize thread pool.\n”,argv[0]);
return EXIT_FAILURE;
}
if ((code1 = pulse_attach (dpp, MSG_FLAG_ALLOC_PULSE, 0, pulse_input, my_arg1)) == -1 ||
(code2 = pulse_attach (dpp, MSG_FLAG_ALLOC_PULSE, 0, pulse_input, my_arg2)) == -1)
{
fprintf(stderr, “Unable to attach pulse.\n”);
return EXIT_FAILURE;
}
if ((coid = message_connect(dpp, MSG_FLAG_SIDE_CHANNEL)) == -1 )
{
fprintf(stderr, “Unable to connect.\n”);
return EXIT_FAILURE;
}
sig.sigev_notify= SIGEV_PULSE;
sig.sigev_coid= coid;
sig.sigev_priority= getprio(0);
sig.sigev_code= code1;
sig.sigev_value.sival_int= 0;
if (timer_create(CLOCK_REALTIME, &sig, &tmr))
{
fprintf(stderr, “timer_create.\n”);
return EXIT_FAILURE;
}
if (timer_settime(tmr, 0, &to, 0) == -1)
{
fprintf(stderr, “timer_settime.\n”);
return EXIT_FAILURE;
}
pthread_create (NULL, NULL, worker, NULL);
// Never returns
thread_pool_start(tpp);
return 0;
}
void *
worker (void *arg)
{
int prio = getprio(0);
for(;
{
sleep(1);
MsgSendPulse(coid, prio, code2, 0);
}
}
int
pulse_input(message_context_t *ctp, int code, unsigned flags, void *handle)
{
printf("%s", (char *)handle);
return 0;
}
Alain Bonnefoy <alain.bonnefoy@icbt.com> wrote:
:> You need to use message_connect(). Here’s some pseudo code:
:>
:> timer_code = pulse_attach(dpp, MSG_FLAG_ALLOC_PULSE, 0, my_func, ac);
:> coid = message_connect(dpp, MSG_FLAG_SIDE_CHANNEL);
:>
:> sig.sigev_notify = SIGEV_PULSE;
:> sig.sigev_coid = coid;
:> sig.sigev_priority = getprio();
:> sig.sigev_code = timer_code;
:> sig.sigev_value.sival_int = 0;
:>
:> timer_create(CLOCK_REALTIME, &sig, &tmr);
:> timer_settime(tmr, 0, &to, 0);
:>
:> -seanb
:>
:>
: I tried it, I call the following function after dispatch_create() and
: resmgr_attach(). I haven’t any error during this procedure but nothing
: happens. I don’t know what’s wrong here.
: Unfortunately, psin doesn’t yet display any information about timers.