tags:

views:

219

answers:

1

I have a question similar to This one . But I want to implement this in Linux, using ACE framework. What is the way to do this

+2  A: 

A little more information would help obtain a better answer:

  • Are your worker threads waiting on other events prior to running?
  • How do your threads communicate with one another?
  • Will you always have the ability to terminate gracefully, or are you anticipating having to force terminate some threads?

The other question you mentioned made a very good point:

Typically, the way that a thread terminates is simply to return from the function that defines the thread. Generally, the main thread signals the worker thread to exit using an event object or a simply an integer or boolean value. If the worker thread is waiting in a WaitForSingleObject, you may need to change it to a WaitForMultipleObjects, where one of the objects is an event. The main thread would call SetEvent and the worker thread would wake up and return.

Depending on what you've setup in ACE, you can use interprocess communication from your main thread to your worker threads to tell them to stop, which they would pickup and handle on their next event check. Alternatively, you can use linux's select.

Hope this points you in the right direction.

reshen
@reshen I am currently in design phase. My child threads once start executing they needs to run periodically for performing some work and also they needs to wait for triggers( events in windows) from the parent thread. This events include termination . Anyway this is in windows.I am finding difficulty in identifying similar interfaces in ACE2. Only parent thread needs to communicate with child threads 3. Yes we always have the ability to terminate gracefullyThe other question you have mentioned is exactly what I need to implement using ACE. Can you suggest me similar interfaces in ACE
siri
Disclaimer: I've not used ACE myself, I prefer Boost.If I understand your problem correctly, its not necessarily an ACE issue. In Linux, you need something analogous to Windows Events, such as using sockets and select (see http://linux.die.net/man/2/select_tut). ACE's task class also (see section 5.5 http://www.cs.wustl.edu/~schmidt/PDF/ACE-concurrency.pdf) provides a message queue that can be used to replace events. Another option is to use an ACE Condition. The bottom line is this: there are multiple solutions both using ACE and native linux calls. See which one fits your needs best.
reshen
@resehen what I feel is sockets,select and message queues are basically used for when some IO or data transfer is required.and ACE or linux condition variables is some how odd as I need to have a condition varible for each corresponding event, and multiple threads using the same condition variable with mutex locking is inefficient. May be I should go with ACE thread manager ACE_Thread_Manager::instance ()->cancel_all () for terminating all the threads and ACE event handler in each thread so that they can run periodically.
siri
I took a look at the ACE_Thread_Manager documentation, and cancel_all() seems to be precisely what you're looking for (cancel() would also provide finer grained control if you needed to kill workers in a particular order). I also agree with your conclusions about sockets being heavy for what you need and a myriad of condition variables being inefficient. It sounds like you're headed down the right path.
reshen