473,730 Members | 2,297 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Unknown exception occured for pthread_exit()

We had written an application in which we create worker thread.

So the main thread will create the worker thread. After some time
the child thread(Worker thread) will call pthread_exit().
This function was written in try{} and there occured an and is handled
in catch(...) handler.

Can any one tell me the reason why the exception occured.

This is on Linux platform.
The Implementation of the code is as follows:
This is a simple form of our application, Try to run this small piece
of code.

The output of this is " FATAL: exception not rethrown
Inside catch... Aborted"

#include <stdio.h>
#include <stdlib.h>
#include <stdexcept.h>
#include <pthread.h>

using namespace std;

void print_message_f unction( void *ptr );
int main()
{
pthread_t thread1;
char *message1 = "Thread 1";
int iret1;

iret1 = pthread_create( &thread1, NULL, (void*(*)
(void*))&print_ message_functio n, (void*) message1);

pthread_join( thread1, NULL);
}

void print_message_f unction( void *ptr )
{
char *message;
message = (char *) ptr;

try
{
pthread_exit((v oid*) 1);
}
catch(...)
{
printf("Inside catch...\n");
}
}


Nov 28 '07 #1
4 4570
le************* ******@gmail.co m wrote:
We had written an application in which we create worker thread.

So the main thread will create the worker thread. After some time
the child thread(Worker thread) will call pthread_exit().
This function was written in try{} and there occured an and is handled
in catch(...) handler.

Can any one tell me the reason why the exception occured.

This is on Linux platform.
Somebody in the Linux newsgroup probably can [tell you the reason].

Another possibility to find some information is to post to a POSIX
newsgroup, since you're using POSIX threads. But I'd go with the
Linux newsgroup first.
[..]
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Nov 28 '07 #2
le************* ******@gmail.co m wrote:
We had written an application in which we create worker thread.

So the main thread will create the worker thread. After some time
the child thread(Worker thread) will call pthread_exit().
This function was written in try{} and there occured an and is handled
in catch(...) handler.

Can any one tell me the reason why the exception occured.
I give you a rough picture, because the posix people usually claim that
they've never heard of C++:

Some implementations of pthreads support cleanup of C++ stackframes
during cancellation. They basically throw a hidden exception back to
the routine that launched the thread procedure, thereby invoking all
destructors. catch(...) catches this exception, of course, may perform
cleanup, but must rethrow the exception, because flowing out out the
handler would mean that the cancellation is cancelled, which isn't
supported.

So for you, this is correct:
catch(...)
{
printf("Inside catch...\n");
throw;
}
--
IYesNo yes=YesNoFactor y.getFactoryIns tance().YES;
yes.getDescript ion().equals(ar ray[0].toUpperCase()) ;
Nov 28 '07 #3
Marco Manfredini wrote:
during cancellation. They basically throw a hidden exception back to
the routine that launched the thread procedure, thereby invoking all
~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~

Not *your* routine, some routine inside of the pthreads library that
invoked the function pointer you gave to pthread_create.
--
IYesNo yes=YesNoFactor y.getFactoryIns tance().YES;
yes.getDescript ion().equals(ar ray[0].toUpperCase()) ;
Nov 28 '07 #4
On Nov 28, 3:06 pm, leelaprasad.gor rep...@gmail.co m wrote:
We had written an application in which we create worker thread.
So the main thread will create the worker thread. After some time
the child thread(Worker thread) will call pthread_exit().
This function was written in try{} and there occured an and is handled
in catch(...) handler.
Can any one tell me the reason why the exception occured.
This is on Linux platform.
The Implementation of the code is as follows: This is a simple
form of our application, Try to run this small piece of code.
This is an OS issue; you'll have to ask in a Linux group. (The
code works perfectly well under Solaris, both with g++ and with
Sun CC.) Off hand, I'd guess there is an error somewhere in
either the OS or the g++ implementation on that platform which
causes some interaction between exceptions and thread
cancelation.
The output of this is " FATAL: exception not rethrown
Inside catch... Aborted"
For what it's worth, the code below isn't legal C++, and won't
generally compile. (I couldn't get it to compile anywhere
without some modifications, and in other places, g++ only
compiles it because of a bug.)
#include <stdio.h>
#include <stdlib.h>
#include <stdexcept.h>
There's no such header.
#include <pthread.h>
using namespace std;
void print_message_f unction( void *ptr );
And since you pass the address of this function to
pthread_create, the signature must be:

extern "C" void* print_message_f unction( void* ) ;

Without the `extern "C"', the code won't compile with a
conformant compiler. (This is a known bug in g++.) And having
the function return void, then casting the pointer, causes
undefined behavior.
int main()
{
pthread_t thread1;
char *message1 = "Thread 1";
And of course, this should be
char const* message1 = ...
(even if it requires a const_cast in the pthread_create:-).)
int iret1;
iret1 = pthread_create( &thread1, NULL, (void*(*)
(void*))&print_ message_functio n, (void*) message1);
The fact that you require the casts here should tell you that
you've done something wrong.
pthread_join( thread1, NULL);
}
void print_message_f unction( void *ptr )
{
char *message;
message = (char *) ptr;
try
{
pthread_exit((v oid*) 1);
}
catch(...)
{
printf("Inside catch...\n");
}

}
More generally, the interaction between pthread_cancel and
destructors isn't well defined (and pthread_exit() does the
equivalent of a pthread_cancel) ; the behavior is different
between g++ and Sun CC, even under Solaris. In the end, I'd say
that it's better to avoid them, and just return from your thread
function.

--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Nov 29 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
3689
by: Ritz, Bruno | last post by:
hi in java i found that when a method has a throws clause in the definition, callers must either handle the exceptions thrown by the method they are calling or "forward" the exception to the caller by specifying a throws clause as well. is there a similar machanism in c++? i want to force a developer to write handlers for all possible exceptions a method of my class library can throw.
2
346
by: jon morgan | last post by:
Hi, Just how do you track down the location of an exception when all you get is a message saying "NullReferenceException occured in Unknown Module" ? It seems like the proverbial needle in a haystack when the debugger doesn't show you the line in your program that triggered the external error. Thanks for any help
0
1595
by: Nick | last post by:
In the last days I've found this error more and more often, but it never occured before and I didn't make any important change in the scripts (it's a CMS developed by me ant it works with no problem in other servers).It's quite a riddle, because web pages work correctly for hours and then, all of a sudden, the error occours. Can anyone help me? (the original was in italian) event type: Error event source: Active Server Pages
5
2226
by: Jacek Dziedzic | last post by:
Hi! In my main() function I have a last-resort exception construct that looks like this: int main() { try { // ... program code }
5
20445
by: Lars-Erik Aabech | last post by:
Hi! Guess it's my day again.. Tried to deploy a test release of a new asp.net web today, and got a terrible error. The web is running swell on three development computers, but when it's copied to the test server it won't work at all. Looks like aspnet_wp is trying to compile it for five seconds, then it stops working what so ever. The system event log gets the following entry: Application popup: aspnet_wp.exe - Application Error : The...
2
4821
by: oopaevah | last post by:
I am using the Microsoft.XMLHTTP object to make server requests ie; ajax. This is working 99% of the time but occasionally it will freeze at the server for 5 minutes and then raise a javascript exception "Unknown name". After the exception I can run the same request ok, and keep doing so until the next time it freezes for 5 minutes. What does the "Unknown name" javascript exception mean?
9
2467
by: Frawls | last post by:
Hi I Am am having problems with a stored Procedure that i wrote. Basically whats happening is that the Stored procedure Runs fine when i EXECUTE it in SQL Query analyzer. But when i debug through the application in Visual Studio .NET 2003 the application an exception when it executes the query.
0
1576
by: platso | last post by:
We had written an application in which we create worker thread. So the main thread will create the worker thread. After some time the child thread(Worker thread) will call pthread_exit(). This function was written in try{} and there occured an exception and is handled in catch(...) handler.
1
2813
by: platso | last post by:
We had written an application in which we create worker thread. So the main thread will create the worker thread. After some time the child thread(Worker thread) will call pthread_exit(). This function was written in try{} and there occured an exception and is handled in catch(...) handler.
0
8943
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8770
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9442
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9301
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9229
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9176
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4801
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3257
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2175
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.