Connecting Tech Pros Worldwide Help | Site Map

Assert in Threads

 
LinkBack Thread Tools Search this Thread
  #1  
Old September 25th, 2007, 03:45 PM
hyderabadblues
Guest
 
Posts: n/a
Default Assert in Threads

Hi ,

I have a doubt regarding the asserts. I have multiple threads running,
is there any chance that there can be assert in two threads at the
same time.


  #2  
Old September 25th, 2007, 06:05 PM
Ron AF Greve
Guest
 
Posts: n/a
Default Re: Assert in Threads

Hi,

"hyderabadblues" <sirishkumar@gmail.comwrote in message
news:1190735043.153765.65470@d55g2000hsg.googlegro ups.com...
Quote:
Hi ,
>
I have a doubt regarding the asserts. I have multiple threads running,
is there any chance that there can be assert in two threads at the
same time.
>
I think that depends on how buggy your programs are ;-)


Regards, Ron AF Greve

http://www.InformationSuperHighway.eu


  #3  
Old September 25th, 2007, 11:15 PM
Jim Langston
Guest
 
Posts: n/a
Default Re: Assert in Threads

"hyderabadblues" <sirishkumar@gmail.comwrote in message
news:1190735043.153765.65470@d55g2000hsg.googlegro ups.com...
Quote:
Hi ,
>
I have a doubt regarding the asserts. I have multiple threads running,
is there any chance that there can be assert in two threads at the
same time.
OT and I don't believe an Assert halts all threads, so yes. But I'm not
sure, you should ask in a thread newsgroup such as comp.programming.threads
where they would know.


  #4  
Old September 26th, 2007, 10:05 AM
James Kanze
Guest
 
Posts: n/a
Default Re: Assert in Threads

On Sep 25, 5:44 pm, hyderabadblues <sirishku...@gmail.comwrote:
Quote:
I have a doubt regarding the asserts. I have multiple threads
running, is there any chance that there can be assert in two
threads at the same time.
Sure. The usual access rules apply to any variables used in the
assert (so you may need to protect it with a lock).

Of course, once an assert fails, you're over and done with. A
failed assertion calls abort(), which normally brings the whole
process down with a bang, by means of a SIGABRT. According to
the language standard (and Posix), if there is a signal handler
for this signal, and it returns, "The abort function causes
abnormal program termination to occur, unless the signal SIGABRT
is being caught and the signal handler does not return."

(I'm not sure of all of the details, but under Posix, at least,
the signal is delivered to the process, not just the thread.
I'm also not too sure what happens if one of the threads is in a
sigwait on SIGABRT, either. At least under Solaris, it doesn't
seem that you can successfully catch it with a sigwait, or block
it with pthread_sigmask.)

--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

  #5  
Old September 26th, 2007, 10:05 AM
James Kanze
Guest
 
Posts: n/a
Default Re: Assert in Threads

On Sep 26, 1:06 am, "Jim Langston" <tazmas...@rocketmail.comwrote:
Quote:
"hyderabadblues" <sirishku...@gmail.comwrote in message
Quote:
news:1190735043.153765.65470@d55g2000hsg.googlegro ups.com...
Quote:
Quote:
I have a doubt regarding the asserts. I have multiple
threads running, is there any chance that there can be
assert in two threads at the same time.
Quote:
OT and I don't believe an Assert halts all threads, so yes.
Not really OT, threads are very much a part of C++, even if they
aren't (yet) specified in the standard. And assert definitly
kills the process (not just the thread) under Posix, and I
suspect also under Windows.

--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

  #6  
Old September 26th, 2007, 10:55 PM
R Samuel Klatchko
Guest
 
Posts: n/a
Default Re: Assert in Threads

hyderabadblues wrote:
Quote:
I have a doubt regarding the asserts. I have multiple threads running,
is there any chance that there can be assert in two threads at the
same time.
That would depend on the specific implementation of assert and what you
consider an assertion occurrence to be. In that second point, is an
assertion failure is not an atomic event, do you consider an assertion
to be when the assertion first fails or when the process exits?

Consider this potential implementation of assert:

#define assert(expr) \
if (!(expr)) { \
assert_output(__FILE__, __LINE_, #expr); \
abort(); \
}

Assume once abort() begins, that no other thread will run.

It's possible that two threads could simultaneously evaluate an asserts
expression to false and both be able to output their log message. But
only one of the threads call to abort() will occur while the other
thread will be stopped before being able to call abort().

samuel
  #7  
Old September 27th, 2007, 09:55 AM
James Kanze
Guest
 
Posts: n/a
Default Re: Assert in Threads

On Sep 27, 12:46 am, R Samuel Klatchko <r...@moocat.orgwrote:
Quote:
Consider this potential implementation of assert:
Quote:
#define assert(expr) \
if (!(expr)) { \
assert_output(__FILE__, __LINE_, #expr); \
abort(); \
}
Just a nit, but that's not a legal implementation. The
expansion of assert() must result in an expression with type
void. (It can be used before the comma operator, for example.)
The typical implementation might be something like:

extern int assert_failed( char const*, int, char const* ) ;
#undef assert
#ifndef NDEBUG
#define assert( expr ) \
(void)( (expr) || assert_failed( __FILE__, __LINE__, #expr ) )
#else
#define assert( expr ) ((void)0)
#endif

The call to abort() would be in assert_failed().

--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,840 network members.