Usage of c++ monitor wrapper Topic is solved

Report here problems in any of ChibiOS components. This forum is NOT for support.
alexacw
Posts: 3
Joined: Wed Jul 03, 2019 4:10 pm
Has thanked: 1 time

Usage of c++ monitor wrapper  Topic is solved

Postby alexacw » Wed Jul 03, 2019 5:20 pm

I am confused on how to use the monitor class.
From what I have learnt, a monitor is used to guard data and allow threads to wait for their change, where modification and observation to the data is only done when the mutex is held.
However the monitor class inherited mutex with "protected" making it impossible to be locked, and it only provides wait, signal and broadcast functions.
I wonder whether this is a intended behavior.

In addition, I would like to be advised on how to "wait on multiple condition variables", where anyone of the condition variable can wake up the suspended thread notifying the signaled conditional variable.

Thank you very much.

User avatar
Giovanni
Site Admin
Posts: 14455
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: Usage of c++ monitor wrapper

Postby Giovanni » Wed Jul 03, 2019 5:30 pm

Hi,

Apparently the monitor class is not complete, it should expose its own lock/unlock to outside.

About the condition variable, you don't need more than one, wait for the variable to be signaled then check one or more conditions to be satisfied.

Moving in "bug reports" about the monitor class.

Giovanni

alexacw
Posts: 3
Joined: Wed Jul 03, 2019 4:10 pm
Has thanked: 1 time

Re: Usage of c++ monitor wrapper

Postby alexacw » Wed Jul 03, 2019 5:41 pm

Giovanni wrote:Hi,

Apparently the monitor class is not complete, it should expose its own lock/unlock to outside.

About the condition variable, you don't need more than one, wait for the variable to be signaled then check one or more conditions to be satisfied.

Moving in "bug reports" about the monitor class.

Giovanni


Thanks for your quick reply.

However I think that it is not feasible to wait only on one condition variable in the use case when a thread has to response to the change of multiple separate data structures, as the thread will only be notified by on of the variables. I can use the event system to be notified by multiple events and protect data with mutexes however, so NVM if the conidition variable doesn't suit this use case.

User avatar
Giovanni
Site Admin
Posts: 14455
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: Usage of c++ monitor wrapper

Postby Giovanni » Wed Jul 03, 2019 7:04 pm

OK, I looked at it again and I was wrong... I haven't touched this for a while.

It is a template class and you can have multiple condition variables. You need to instantiate it in your class from which lock/unlock are accessible.

Giovanni

alexacw
Posts: 3
Joined: Wed Jul 03, 2019 4:10 pm
Has thanked: 1 time

Re: Usage of c++ monitor wrapper

Postby alexacw » Thu Jul 04, 2019 1:25 am

Giovanni wrote:OK, I looked at it again and I was wrong... I haven't touched this for a while.

It is a template class and you can have multiple condition variables. You need to instantiate it in your class from which lock/unlock are accessible.

Giovanni


I see, so that's mean we are supposed to inherit the monitor with data members and implement accessor functions.
Thanks.


Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 9 guests