33 #include <boost/thread/mutex.hpp> 34 #include <boost/thread/condition.hpp> 46 boost::mutex::scoped_lock lock(
iomutex);
47 std::cerr <<
"Creating message [" <<
s <<
"," <<
cmd <<
"]" << std::endl;
56 boost::mutex::scoped_lock lock(
iomutex);
57 std::cerr <<
"Destroying message [" <<
s <<
"," <<
cmd <<
"]" << std::endl;
72 subscriptions[sub_count] = mbox->
subscribe();
73 mboxes[sub_count] = mbox;
80 boost::mutex::scoped_lock lock(
iomutex);
81 std::cerr <<
"Process " << name <<
"got message " << msg->
cmd <<
" " << msg->
s <<
" subcount = " << sub_count <<
" i = " << i << std::endl;
85 if((i + 1) < sub_count) {
93 if((i + 1) < sub_count) {
114 for(i = 0; i < sub_count; i++) {
116 if((msg = (mboxes[i]->
get(subscriptions[i])))) {
118 mboxes[i]->free(msg);
123 if(!flag) usleep(10000);
130 int subscriptions[10];
136 int main(
int argc,
char * argv[])
138 (void) argc; (void) argv;
143 for(i = 0; i < 5; i++) mbox[i] = new SoDa::MultiMBox<SoDaTest::MyMsg>(
false);
152 v[0] = &a; v[1] = &b; v[2] = &c; v[3] = &d; v[4] = &e;
155 for(i = 0; i < 5; i++) {
156 for(j = i; j < 5; j++) {
161 for(i = 0; i < 5; i++) v[i]->start();
The Baseclass for all SoDa objects, and useful commonly used classes.
The Thread baseclass for all SoDa thread objects.
void execute(MyMsg *msg, int i)
int main(int argc, char *argv[])
MultiMBox_Test_Thread(const std::string &n)
MyMsg(const std::string ss, CMD _c)
void subscribe(SoDa::MultiMBox< MyMsg > *mbox)
void run()
Each thread object must define its "run" loop.