Mutex/Condition Variable and SRR Blocking?

Can I use both a mutex (or condition variable) and SRR as the blocking
mechanism of a thread, or must I choose one or the other? If it can be done,
how?

Thanks,
Marty Doane
Siemens Dematic

Marty Doane <marty.doane@rapistan.com> wrote:

Can I use both a mutex (or condition variable) and SRR as the blocking
mechanism of a thread, or must I choose one or the other? If it can be done,
how?

A thread can only block on one thing at a time. This means that if you are
blocked, waiting for a message, and your condvar gets signalled, nothing
of interest will happen :slight_smile:

Same thing the other way around, if you are blocked on a condvar and a message
arrives, nothing will happen.

Generally, you’ll want to allocate multiple threads; one for each blocking
method, and then have them obtain some common mutex if required to perform
their functionality…

Cheers,
-RK


Robert Krten, PARSE Software Devices +1 613 599 8316.
Realtime Systems Architecture, Books, Video-based and Instructor-led
Training and Consulting at www.parse.com.
Email my initials at parse dot com.

That what I thought. Thanks for the confirmation.

“Robert Krten” <nospam90@parse.com> wrote in message
news:a40n5t$ks9$3@inn.qnx.com

Marty Doane <> marty.doane@rapistan.com> > wrote:
Can I use both a mutex (or condition variable) and SRR as the blocking
mechanism of a thread, or must I choose one or the other? If it can be
done,
how?

A thread can only block on one thing at a time. This means that if you
are
blocked, waiting for a message, and your condvar gets signalled, nothing
of interest will happen > :slight_smile:

Same thing the other way around, if you are blocked on a condvar and a
message
arrives, nothing will happen.

Generally, you’ll want to allocate multiple threads; one for each blocking
method, and then have them obtain some common mutex if required to perform
their functionality…

Cheers,
-RK


Robert Krten, PARSE Software Devices +1 613 599 8316.
Realtime Systems Architecture, Books, Video-based and Instructor-led
Training and Consulting at > www.parse.com> .
Email my initials at parse dot com.

Be carefull too to avoid a deadly embrace.


Bill Caroselli – 1(626) 824-7983
Q-TPS Consulting
QTPS@EarthLink.net


“Robert Krten” <nospam90@parse.com> wrote in message
news:a40n5t$ks9$3@inn.qnx.com

Marty Doane <> marty.doane@rapistan.com> > wrote:
Can I use both a mutex (or condition variable) and SRR as the blocking
mechanism of a thread, or must I choose one or the other? If it can be
done,
how?

A thread can only block on one thing at a time. This means that if you
are
blocked, waiting for a message, and your condvar gets signalled, nothing
of interest will happen > :slight_smile:

Same thing the other way around, if you are blocked on a condvar and a
message
arrives, nothing will happen.

Generally, you’ll want to allocate multiple threads; one for each blocking
method, and then have them obtain some common mutex if required to perform
their functionality…

Cheers,
-RK


Robert Krten, PARSE Software Devices +1 613 599 8316.
Realtime Systems Architecture, Books, Video-based and Instructor-led
Training and Consulting at > www.parse.com> .
Email my initials at parse dot com.

Is that when your wife walks in while…

:–)

“Bill Caroselli” <qtps@earthlink.net> wrote in message
news:a41064$rk6$1@inn.qnx.com

Be carefull too to avoid a deadly embrace.


Bill Caroselli – 1(626) 824-7983
Q-TPS Consulting
QTPS@EarthLink.net


“Robert Krten” <> nospam90@parse.com> > wrote in message
news:a40n5t$ks9$> 3@inn.qnx.com> …
Marty Doane <> marty.doane@rapistan.com> > wrote:
Can I use both a mutex (or condition variable) and SRR as the blocking
mechanism of a thread, or must I choose one or the other? If it can be
done,
how?

A thread can only block on one thing at a time. This means that if you
are
blocked, waiting for a message, and your condvar gets signalled, nothing
of interest will happen > :slight_smile:

Same thing the other way around, if you are blocked on a condvar and a
message
arrives, nothing will happen.

Generally, you’ll want to allocate multiple threads; one for each
blocking
method, and then have them obtain some common mutex if required to
perform
their functionality…

Cheers,
-RK


Robert Krten, PARSE Software Devices +1 613 599 8316.
Realtime Systems Architecture, Books, Video-based and Instructor-led
Training and Consulting at > www.parse.com> .
Email my initials at parse dot com.

I see you have experience.

“Marty Doane” <marty.doane@rapistan.com> wrote in message
news:a41193$slt$1@inn.qnx.com

Is that when your wife walks in while…

:–)

“Bill Caroselli” <> qtps@earthlink.net> > wrote in message
news:a41064$rk6$> 1@inn.qnx.com> …
Be carefull too to avoid a deadly embrace.

Hey!!! I’m VERY happily married. Play nice now.

“Bill Caroselli” <qtps@earthlink.net> wrote in message
news:a414dm$1pm$1@inn.qnx.com

I see you have experience.

“Marty Doane” <> marty.doane@rapistan.com> > wrote in message
news:a41193$slt$> 1@inn.qnx.com> …
Is that when your wife walks in while…

:–)

“Bill Caroselli” <> qtps@earthlink.net> > wrote in message
news:a41064$rk6$> 1@inn.qnx.com> …
Be carefull too to avoid a deadly embrace.

I though I was too.

“Marty Doane” <marty.doane@rapistan.com> wrote in message
news:a41a11$5bo$1@inn.qnx.com

Hey!!! I’m VERY happily married. Play nice now.

“Bill Caroselli” <> qtps@earthlink.net> > wrote in message
news:a414dm$1pm$> 1@inn.qnx.com> …
I see you have experience.

“Marty Doane” <> marty.doane@rapistan.com> > wrote in message
news:a41193$slt$> 1@inn.qnx.com> …
Is that when your wife walks in while…

:–)

“Bill Caroselli” <> qtps@earthlink.net> > wrote in message
news:a41064$rk6$> 1@inn.qnx.com> …
Be carefull too to avoid a deadly embrace.

\

Mutex/condvars are usually used for mutual exclusion. SRR is usually
use for sync. IPC. What are you trying to do?

Marty Doane <marty.doane@rapistan.com> wrote:

Can I use both a mutex (or condition variable) and SRR as the blocking
mechanism of a thread, or must I choose one or the other? If it can be done,
how?

Thanks,
Marty Doane
Siemens Dematic


Kirk Russell Bridlewood Software Testers Guild

The immediate issue was timers, but more than that I’m trying to get all the
choices straight in my head as I plan a system architecture for a
multithreadded application.

Required interfaces:

  • 4 serial ports
  • multiple TCP socket connections
  • at least one UDP socket

Each serial port connects to an RS-485 bus with to up to 127 devices. For
each device there’s a sense of a session which requires timeout detection.

The application of condvar I was envisioning was to manage interthread
buffering of messages. I was wondering if I could also do timer management
within a thread that blocks waiting for incoming condvar-based interthread
messages. I now think not.

Marty Doane
Siemens Dematic

“kirk” <kirussel@NOSPAMrogers.com> wrote in message
news:a41udf$ieb$1@inn.qnx.com

Mutex/condvars are usually used for mutual exclusion. SRR is usually
use for sync. IPC. What are you trying to do?

Marty Doane <> marty.doane@rapistan.com> > wrote:
Can I use both a mutex (or condition variable) and SRR as the blocking
mechanism of a thread, or must I choose one or the other? If it can be
done,
how?

Thanks,
Marty Doane
Siemens Dematic


Kirk Russell Bridlewood Software Testers Guild

Gloups! same situation ;o)
Bill Caroselli wrote:

I though I was too.

“Marty Doane” <> marty.doane@rapistan.com> > wrote in message
news:a41a11$5bo$> 1@inn.qnx.com> …

Hey!!! I’m VERY happily married. Play nice now.

“Bill Caroselli” <> qtps@earthlink.net> > wrote in message
news:a414dm$1pm$> 1@inn.qnx.com> …

I see you have experience.

“Marty Doane” <> marty.doane@rapistan.com> > wrote in message
news:a41193$slt$> 1@inn.qnx.com> …

Is that when your wife walks in while…

:–)

“Bill Caroselli” <> qtps@earthlink.net> > wrote in message
news:a41064$rk6$> 1@inn.qnx.com> …

Be carefull too to avoid a deadly embrace.

\

Using mutex/condvars to control access to a interthread queue is an accepted
practice. If the resolution of the timers doesn’t have to be fine, you
create a timer thread that injects a “timer message” into the interthread
queue. Then the threads, blocking for events in the queue, have the
simple/same interface for messages/timeouts. Instead of the timer
thread, you could pthread_cond_timedwait() to setup your timer and
block for the next message at the same time.

Instead of a interthread queue, you could use sync. realtime signals.
Using sync. signals is fast – no signal handlers involved. And realtime
signals can be queued with data (a pointer). The threads, blocking for
events, would call sigwaitinfo(). Signals, representing data, would
contain a pointer to the message. For timers, just use the functions
that manage SIGALRM. This is nice because the kernel does the queueing
(but could be slower because of more kernel calls). Again, the blocking
threads have the same simple interface for messages/timeouts.

You could use SRR for this also. You can configure pulses to be sent
to a channel when a timer expires. And you also get the same interface
for the messages/timeouts. But if you use SRR, the data will be copied –
seems like a waste since the data is already in your address space.

So, I guess it depends on which API you are familiar with. That is
why I like Neutrino – the API is rich enough to tackle these problems
in a number of ways. I remember writing a similar app (serial ports
and sockets) with SVR3 – what a pain :slight_smile:

Marty Doane <marty.doane@rapistan.com> wrote:

The immediate issue was timers, but more than that I’m trying to get all the
choices straight in my head as I plan a system architecture for a
multithreadded application.

Required interfaces:

  • 4 serial ports
  • multiple TCP socket connections
  • at least one UDP socket

Each serial port connects to an RS-485 bus with to up to 127 devices. For
each device there’s a sense of a session which requires timeout detection.

The application of condvar I was envisioning was to manage interthread
buffering of messages. I was wondering if I could also do timer management
within a thread that blocks waiting for incoming condvar-based interthread
messages. I now think not.

Marty Doane
Siemens Dematic

[…]