Please help me, how to make a milti-threaded system, where two of threads should be synchronized, while other threads should be not disturbed.
I see 2 possible solutions (maybe I'm wrong):
1) Thread1 makes data filtering and send Event1 or Event2 (depends from data values) to Thread2. Where Thread2 sleeps until Event1 or Event2 and then executes something corresponding to Event number.
2) Thread1 parses data and send event and Message1 or Message2 (depends from data) to Thread2. Where Thread2 sleeps until event and then executes something corresponding to Message number.
Here is code sample for better understanding:
Code: Select all
static msg_t Thread1(void *arg)
{
(void)arg;
int data
chRegSetThreadName("data_filter");
while (TRUE) {
data = get_data();
if (data == TYPE1) {
// Send Event1 only to Thread2.
// Or send Event and Message1 to Thread2?
} else if (data == TYPE2) {
// Send Event2 only to Thread2.
// Or send Event and Message2 only to Thread2?
}
}
return 0;
}
static msg_t Thread2(void *arg)
{
(void)arg;
chRegSetThreadName("relay1_set");
while (TRUE) {
// Wait for Event1/Event2, which is specific only to this thread.
// Or alternatively wait for specific Event with one of messages.
if (Event1) // Message1 instead?
relay_set();
else if (Event2) // Message2 instead?
relay_clear();
}
return 0;
}
Please edit this code sample to show how exactly events and/or messages should be registered, sent and dispatched.
Best wishes.
--
Igor