Sorry Steven !

Yes I was in my problem an sincerely, I don’t see how you could
understand what I mean with the infos I gave!

So, I 'm going to be more clear!!!

Consider a server application developped as a ressource manager,
able to receive IO_MSG and able to create a thread to do something,
depending on the received message.
the message type is:

In the application we have:

for_ever{
ctp = dispatch_block(ctp);

dispatch_handler(ctp);
}


Until here it’s good, the code above is my main thread !

Now, I receive an io_msg and according to its meanning, my ressource
manager call a function io_msg() to perform the request.
In that function, I do:

io_msg()
{

Dialogue()

return(RESMGR_NOREPLY);
}


Dialogue()
{

chid = ChannelCreate(0);
coid = ConnectAttach(…,NTO_SIDE_CHANNEL);
timer_create(…);
pthread_create(&thread,…);

MsgReceive(…); ← here I get a pulse because the timer fire.

pthread_cancel(thread);
ConnectDetach(coid);
timer_delete();
channelDestroy();
ReplyMsg();
}

At the end of that last function I go back to io_msg() to
return(RESMGR_NOREPLY), then to the main loop where I return from
dispatch_block() with a message value of 0 (I was waiting for an
IO_CLOSE, 116) and when I enter dispatch_handler(), the program exits
with:

No such process

I don’t which process dispatch_handler() is talking about?

I don’t know if it’s enough precise but my code is a little bit long and
I don’t know if I can send it to you.
Tell me if you want it.

Thanks
Alain.

Alain Bonnefoy <alain.bonnefoy@icbt.com> wrote:

Yes I was in my problem an sincerely, I don’t see how you could
understand what I mean with the infos I gave!

So, I 'm going to be more clear!!!

Consider a server application developped as a ressource manager,
able to receive IO_MSG and able to create a thread to do something,
depending on the received message.
the message type is:

In the application we have:

for_ever{
ctp = dispatch_block(ctp);

dispatch_handler(ctp);
}

Until here it’s good, the code above is my main thread !

Now, I receive an io_msg and according to its meanning, my ressource
manager call a function io_msg() to perform the request.
In that function, I do:

io_msg()
{

Dialogue()

return(RESMGR_NOREPLY);
}



Dialogue()
{

chid = ChannelCreate(0);
coid = ConnectAttach(…,NTO_SIDE_CHANNEL);
timer_create(…);
pthread_create(&thread,…);

MsgReceive(…); ← here I get a pulse because the timer fire.

pthread_cancel(thread);
ConnectDetach(coid);
timer_delete();
channelDestroy();
ReplyMsg();
}

At the end of that last function I go back to io_msg() to
return(RESMGR_NOREPLY), then to the main loop where I return from
dispatch_block() with a message value of 0 (I was waiting for an
IO_CLOSE, 116)

This is just a question of timing. When you return from Dialogue()
you will get _PULSE_CODE_THREADDEATH for the death of the thread,
you will get _PULSE_CODE_DISCONNECT for the ConnectDetach(),
and when your client closes, you will get _IO_CLOSE. In the
case of _PULSE_CODE_THREADDEATH, dispatch_handler() will return
-1. This is expected. More on this below.

and when I enter dispatch_handler(), the program exits
with:

No such process

I don’t which process dispatch_handler() is talking about?

I don’t know if it’s enough precise but my code is a little bit long and
I don’t know if I can send it to you.
Tell me if you want it.

Here’s a guess at what is going wrong. You are doing the following:

if (dispatch_handler(ctp) == -1) {

exit(…);
}

And if so, is it the exit() function that is exiting? Put a printf()
before exit() and you will see.

dispatch_handler() is expected to return -1 under some
circumstances so you should not exit. Do not look at errno
in this case as dispatch_handler() does not set it.

dispatch_handler() will return -1 if:
. the message was a _PULSE_CODE_THREADDEATH pulse message
(see ChannelCreate()) for which there is no default handler
** Alain, this is the one you are getting when your thread is cancelled
. the message length was less than 2 bytes, a 2 byte message
type is wanted at the beginning of the message so that a
handler can be looked for
. the message was not in native endian format and even
though a handler was registered for it using message_attach(),
the MSG_FLAG_CROSS_ENDIAN flag was not given to
message_attach()
. a handler was found for the message but the handler
determined that there was a problem
In any case, if the message was not a pulse then the client
will have been replied to with an appropriate errno.

The reason you are getting _PULSE_CODE_THREADDEATH is because the thread
that you create dies. See _NTO_CHF_THREAD_DEATH in the docs for the
ChannelCreate() function for more on this.

Thanks
Alain.

Steven Dufresne a écrit :

Alain Bonnefoy <> alain.bonnefoy@icbt.com> > wrote:
Yes I was in my problem an sincerely, I don’t see how you could
understand what I mean with the infos I gave!

So, I 'm going to be more clear!!!

Consider a server application developped as a ressource manager,
able to receive IO_MSG and able to create a thread to do something,
depending on the received message.
the message type is:

In the application we have:

for_ever{
ctp = dispatch_block(ctp);

dispatch_handler(ctp);
}

Until here it’s good, the code above is my main thread !

Now, I receive an io_msg and according to its meanning, my ressource
manager call a function io_msg() to perform the request.
In that function, I do:

io_msg()
{

Dialogue()

return(RESMGR_NOREPLY);
}

Dialogue()
{

chid = ChannelCreate(0);
coid = ConnectAttach(…,NTO_SIDE_CHANNEL);
timer_create(…);
pthread_create(&thread,…);

MsgReceive(…); ← here I get a pulse because the timer fire.

pthread_cancel(thread);
ConnectDetach(coid);
timer_delete();
channelDestroy();
ReplyMsg();
}

At the end of that last function I go back to io_msg() to
return(RESMGR_NOREPLY), then to the main loop where I return from
dispatch_block() with a message value of 0 (I was waiting for an
IO_CLOSE, 116)

This is just a question of timing. When you return from Dialogue()
you will get _PULSE_CODE_THREADDEATH for the death of the thread,
you will get _PULSE_CODE_DISCONNECT for the ConnectDetach(),
and when your client closes, you will get _IO_CLOSE. In the
case of _PULSE_CODE_THREADDEATH, dispatch_handler() will return
-1. This is expected. More on this below.

and when I enter dispatch_handler(), the program exits
with:

No such process

I don’t which process dispatch_handler() is talking about?

I don’t know if it’s enough precise but my code is a little bit long and
I don’t know if I can send it to you.
Tell me if you want it.

Here’s a guess at what is going wrong. You are doing the following:

if (dispatch_handler(ctp) == -1) {

exit(…);
}

And if so, is it the exit() function that is exiting? Put a printf()
before exit() and you will see.

dispatch_handler() is expected to return -1 under some
circumstances so you should not exit. Do not look at errno
in this case as dispatch_handler() does not set it.

dispatch_handler() will return -1 if:
. the message was a _PULSE_CODE_THREADDEATH pulse message
(see ChannelCreate()) for which there is no default handler
** Alain, this is the one you are getting when your thread is cancelled
. the message length was less than 2 bytes, a 2 byte message
type is wanted at the beginning of the message so that a
handler can be looked for
. the message was not in native endian format and even
though a handler was registered for it using message_attach(),
the MSG_FLAG_CROSS_ENDIAN flag was not given to
message_attach()
. a handler was found for the message but the handler
determined that there was a problem
In any case, if the message was not a pulse then the client
will have been replied to with an appropriate errno.

The reason you are getting _PULSE_CODE_THREADDEATH is because the thread
that you create dies. See _NTO_CHF_THREAD_DEATH in the docs for the
ChannelCreate() function for more on this.

Thanks
Alain.

That’s ok!!
Using pulse_attach() on _PULSE_CODE_THREADDEATH prevent dispatch_handler()
returning -1.

Thanks Steven
Alain.