Connecting Tech Pros Worldwide Help | Site Map

Assert in Threads

hyderabadblues
Guest
 
Posts: n/a
#1: Sep 25 '07
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.

Ron AF Greve
Guest
 
Posts: n/a
#2: Sep 25 '07

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


Jim Langston
Guest
 
Posts: n/a
#3: Sep 26 '07

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.


James Kanze
Guest
 
Posts: n/a
#4: Sep 26 '07

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

James Kanze
Guest
 
Posts: n/a
#5: Sep 26 '07

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

R Samuel Klatchko
Guest
 
Posts: n/a
#6: Sep 26 '07

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
James Kanze
Guest
 
Posts: n/a
#7: Sep 27 '07

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

Closed Thread