Simple Event Signaling

I am having difficulty with a simple case of wanting a thread to wait on
an event, with a timeout time. The code to implement this in WIN32 is
attached, I was hoping a Neutrino expert could “enlighten” me as to how
to best implement this for Neutrino. What I have seems awful complex
for such a simple task…

Jim

Jim Bormann <james.bormann@delphiauto.com> wrote:

This is a multi-part message in MIME format.
--------------319C0FF4B851A45C517BAB49
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

I am having difficulty with a simple case of wanting a thread to wait on
an event, with a timeout time. The code to implement this in WIN32 is
attached, I was hoping a Neutrino expert could “enlighten” me as to how
to best implement this for Neutrino. What I have seems awful complex
for such a simple task…

Take a look at TimerTimeout() for timing out any blocking state. Also,
what sort of event are you waiting on? MsgReceive() is a common way
to block (for pulse), but for signals, you might make a different choice.

I can’t comment on your code as you seem to have chosen to attach it
in mime-encoded form, rather than as plain text.

-David

Jim

--------------319C0FF4B851A45C517BAB49
Content-Type: application/x-unknown-content-type-c_auto_file;
name=“test.c”
Content-Transfer-Encoding: base64
Content-Disposition: inline;
filename=“test.c”

I2luY2x1ZGUgPHdpbmRvd3MuaD4KI2luY2x1ZGUgPHN0ZGlvLmg+Cg0KI2RlZmluZSBUSFJF
QURfVElNRU9VVCAxMDAwMCAgLyogMTAgc2VjICovCgpzdGF0aWMgdm9sYXRpbGUgaW50IFRo
cmVhZEV4ZWN1dGluZz0wOwpzdGF0aWMgSEFORExFIGhPYmplY3Q7CnN0YXRpYyBjb25zdCBk
b3VibGUgVGhyZWFkVGltZW91dCA9IFRIUkVBRF9USU1FT1VUIC8gMTAwMC4wOwoKLyotLS0t
LS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0t
LS0tLS0tLS0tLS0tLS0tLS0qLwp2b2lkIFRocmVhZEZ1bmModm9pZCkKewoJdW5zaWduZWQg
aW50IFRocmVhZENvdW50ZXI9MDsKCXdoaWxlICgxKSB7CgkJRFdPUkQgU3RhdHVzOwoJC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jcmVhdGUgdGhyZWFkXG4i
LCBzdGRlcnIpOwoJCXJldHVybiAxOwoJfQoJZWxzZSB7CgkJZnB1dHMoIlByZXNzIGFueSBr
ZXkgdG8gc2lnbmFsIHRocmVhZCwgRVNDIHRvIGV4aXRcbiIsc3Rkb3V0KTsNCgkJZmZsdXNo
KHN0ZG91dCk7DQoJCXdoaWxlICgxKSB7CgkJCWlmIChnZXRjaCgpID09IDB4MUIpIHsKCQkJ
CWZwdXRzKCJUZXJtaW5hdGluZyB0aHJlYWQuLi5cblByZXNzIGFueSBrZXkgdG8gY2xvc2Ui
LHN0ZG91dCk7CgkJCQl3aGlsZSAoVGhyZWFkRXhlY3V0aW5nKSB7DQoJCQkJCS8qIHdhaXQg
Zm9yIHRocmVhZCB0byBzbGVlcCAqLw0KCQkJCX0NCgkJCQlUZXJtaW5hdGVUaHJlYWQoaFRo
cmVhZCwwKTsNCgkJCQlnZXRjaCgpOwoJCQkJYnJlYWs7CgkJCX0KCQkJLyogc2lnbmFsIHRo
ZSB0aHJlYWQgdG8gd2FrZSB1cCAqLwoJCQlTZXRFdmVudChoT2JqZWN0KTsKCQl9Cgl9Cgly
ZXR1cm4gMDsKfQovKi0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0t
LS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLSovCg==
--------------319C0FF4B851A45C517BAB49–

Jim Bormann <james.bormann@delphiauto.com> wrote:
: This is a multi-part message in MIME format.
: --------------319C0FF4B851A45C517BAB49
: Content-Type: text/plain; charset=us-ascii
: Content-Transfer-Encoding: 7bit

: I am having difficulty with a simple case of wanting a thread to wait on
: an event, with a timeout time. The code to implement this in WIN32 is
: attached, I was hoping a Neutrino expert could “enlighten” me as to how
: to best implement this for Neutrino. What I have seems awful complex
: for such a simple task…

: Jim

From the above description, I would look at pthread_cond_timedwait().

-seanb

In article <91an31$353$1@nntp.qnx.com>, Sean Boudreau <seanb@qnx.com> wrote:

Jim Bormann <> james.bormann@delphiauto.com> > wrote:
: This is a multi-part message in MIME format.
: --------------319C0FF4B851A45C517BAB49
: Content-Type: text/plain; charset=us-ascii
: Content-Transfer-Encoding: 7bit

: I am having difficulty with a simple case of wanting a thread to wait on
: an event, with a timeout time. The code to implement this in WIN32 is
: attached, I was hoping a Neutrino expert could “enlighten” me as to how
: to best implement this for Neutrino. What I have seems awful complex
: for such a simple task…

: Jim

From the above description, I would look at pthread_cond_timedwait().

That’s funny. From the description, I would have thought Dave’s
TimerTimeout suggestion would cover the most likely situation(s).
Not to mention that a timer can also be configured to generate
a POSIX signal or a QNX Pulse – which can be received by a
MsgReceive – and handled as a timeout.

For signals, there is also sigtimedwait(), to be used in place of
sigwait() or pause().

\


Steve Furr email: furr@qnx.com
QNX Software Systems, Ltd.