Project Home
Project Home
Trackers
Trackers
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - Best way to prevent Main from exiting: (5 Items)
   
Best way to prevent Main from exiting  
Hello,

I have an application that creates a dispatch thread pool and several "services" by using message_attach to add message 
handlers to the system.

Once this is done, there is no main loop since the dispatch handles the message events.

What is the best way to prevent Main from exiting after the setup is done.
Can you use pthread_join() on a thread pool?  (I don't see how)

Currently, I create a while(1) loop that uses sleep(5000), but this is not the best use of system resources.

Thoughts?

Thanks,
- Mike
AW: Best way to prevent Main from exiting  
Hi Mike,

I guess you should give the flag POOL_FLAG_USE_SELF to
thread_pool_create().

Regards,
- Thomas

> -----Ursprungliche Nachricht-----
> Von: Michael Cranston [mailto:community-noreply@qnx.com]
> Gesendet: 01 August 2008 15:27
> An: momentics-community
> Betreff: Best way to prevent Main from exiting
> 
> 
> Hello,
> 
> I have an application that creates a dispatch thread pool and 
> several "services" by using message_attach to add message 
> handlers to the system.
> 
> Once this is done, there is no main loop since the dispatch 
> handles the message events.
> 
> What is the best way to prevent Main from exiting after the 
> setup is done.
> Can you use pthread_join() on a thread pool?  (I don't see how)
> 
> Currently, I create a while(1) loop that uses sleep(5000), 
> but this is not the best use of system resources.
> 
> Thoughts?
> 
> Thanks,
> - Mike
> 
> 
> _______________________________________________
> QNX Momentics Community Support
> http://community.qnx.com/sf/go/post11325
> 
> 
Re: AW: Best way to prevent Main from exiting  
Thanks for the reply.
I should have been a bit more specific.

The application's main function doesn't actually make the thread pool.
I actually spawn a thread to do this which indeed uses the flag you mentioned.

This is done in the constructor of a c++ base class.  My derived app class constructor then sets up other services for 
messages and pulses.

The constructor then exits (back to main) where I can do addition object construction.  When my work in main is done, I 
need a way to prevent it from exiting and destroying the application.

Thoughts?
AW: AW: Best way to prevent Main from exiting  
Usually you'd dedicate that thread to signal handling.
Block all signals for all threads except the 1st one,
ans instead of sleeping, do a sigwaitinfo() in your 
endless loop. Upon receipt of a terminating signal, 
you can then gracefully shut down your program.

- Thomas

> -----Ursprungliche Nachricht-----
> Von: Michael Cranston [mailto:community-noreply@qnx.com]
> Gesendet: 01 August 2008 15:51
> An: momentics-community
> Betreff: Re: AW: Best way to prevent Main from exiting
> 
> 
> Thanks for the reply.
> I should have been a bit more specific.
> 
> The application's main function doesn't actually make the thread pool.
> I actually spawn a thread to do this which indeed uses the 
> flag you mentioned.
> 
> This is done in the constructor of a c++ base class.  My 
> derived app class constructor then sets up other services for 
> messages and pulses.
> 
> The constructor then exits (back to main) where I can do 
> addition object construction.  When my work in main is done, 
> I need a way to prevent it from exiting and destroying the 
> application.
> 
> Thoughts?
> 
> _______________________________________________
> QNX Momentics Community Support
> http://community.qnx.com/sf/go/post11329
> 
> 
Re: AW: AW: Best way to prevent Main from exiting  
Thanks.