exception vs. multiple-thread


 
Thread Tools Search this Thread
Top Forums Programming exception vs. multiple-thread
# 1  
Old 06-05-2007
exception vs. multiple-thread

Some questions regarding exception vs. multiple-thread :

1. there are one main thread and one child thread. the child thread may throw one exception but it doesn't try to catch any exception. in the main thread, it tries to catch excpetion. Can main thread catch the exception that is thrown from child thread?

2. if child tread may throw exception, and neither main tread nor child tread will catch exception. What is the consequence if the child tread really throws one exception. Which tread is crash? Or both crash?


Anyone can help? Thanks.
# 2  
Old 06-06-2007
1. No.

2. Thread *should* exit.

However this all depends on how thread-aware the C++ library is. The best thing to do is for a C++ thread created with pthread_create to have a try/catch(...) block to stop C++ threads trying to unwind through pthread library.

eg

Code:
static void *my_thead(void *arg)
{
    try
    {
       do_funky_stuff();
    }
    catch(...)
    {
    }

    return NULL;
}

Not all platforms support mixing pthread_cleanup_push/pop with C++ local objects.

G++ is appalling with exceptions and threads. For example calling pthread_exit() should cause all local objects to destruct. Sun's Studio11 does this correctly.
Login or Register to Ask a Question

Previous Thread | Next Thread

5 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Catching the exception in multiple logs

Hi folks, I have logs folder in which different type of logs are generated , I am monitoring them by the below command tail -f *.log but I want that if exception come in any of the logs then it should be catch so what i should prefix with tail -f *.log so that it imeediatley catches and... (3 Replies)
Discussion started by: punpun66
3 Replies

2. Shell Programming and Scripting

Monitor logs for exception and if exception come then sent an email

Hi Folks, please advise , I have logs generated on unix machine at location /ops/opt/aaa/bvg.log , now sometimes there come exception in these logs also, so I want to write such a script such that it should continuously monitor these logs and whenever any exception comes that is it try to find... (3 Replies)
Discussion started by: tuntun27272727
3 Replies

3. Programming

creating multiple threads using single thread id

Hi all, Can I create multiple threads using single thread_id like pthread_t thread_id; pthread_create(&thread_id, NULL, &print_xs, NULL); pthread_create(&thread_id, NULL, &print_ys, NULL); pthread_create(&thread_id, NULL, &print_zs, NULL); pthread_join(thread_id, NULL); what... (2 Replies)
Discussion started by: zing_foru
2 Replies

4. Shell Programming and Scripting

FTP GET with exception handeling and multiple conditions

Thanks everyone for the wonderful and helping environment.. And the problem I asked.. forget it... 4 days wait for a decent reply was such a moral booster.. (3 Replies)
Discussion started by: ReignOfChaos
3 Replies

5. IP Networking

Can we write a multiple thread to receive from a single socket file descriptor

Hi Friends, I have written a program which will listener for more than 1000 requests per second from a single socket descriptor and then it will process those requestes. Its taking X amount of time. Now i want to reduce that time. Will I can write multiple threads to receive the... (2 Replies)
Discussion started by: pa.chidhambaram
2 Replies
Login or Register to Ask a Question