473,385 Members | 1,838 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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.

Sep 25 '07 #1
6 4599
Hi,

"hyderabadblues" <si*********@gmail.comwrote in message
news:11*********************@d55g2000hsg.googlegro ups.com...
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
Sep 25 '07 #2
"hyderabadblues" <si*********@gmail.comwrote in message
news:11*********************@d55g2000hsg.googlegro ups.com...
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.
Sep 25 '07 #3
On Sep 25, 5:44 pm, hyderabadblues <sirishku...@gmail.comwrote:
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:ja*********@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

Sep 26 '07 #4
On Sep 26, 1:06 am, "Jim Langston" <tazmas...@rocketmail.comwrote:
"hyderabadblues" <sirishku...@gmail.comwrote in message
news:11*********************@d55g2000hsg.googlegro ups.com...
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.
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:ja*********@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

Sep 26 '07 #5
hyderabadblues wrote:
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
Sep 26 '07 #6
On Sep 27, 12:46 am, R Samuel Klatchko <r...@moocat.orgwrote:
Consider this potential implementation of assert:
#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:ja*********@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

Sep 27 '07 #7

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

Similar topics

28
by: Fábio Mendes | last post by:
I'm sorry if it's an replicate. Either my e-mail program is messing with things or the python-list sent my msg to /dev/null. I couldn't find anything related in previous PEP's, so here it goes a...
11
by: David | last post by:
I am compiling C++ under both MacOsX and under Bloodshed Dev C++ on Windows XP. Because the console window disappears under Bloodshed when using the standard assert() via #include <cassert> I...
27
by: Daniel Vallstrom | last post by:
I'm having problems with inconsistent floating point behavior resulting in e.g. assert( x > 0.0 && putchar('\n') && x == 0.0 ); holding. (Actually, my problem is the dual one where I get...
5
by: Alex Vinokur | last post by:
Here are two programs. --- foo1.c --- #include <assert.h> #define FOO 10 int main() { assert (15 < FOO); return 0; }
13
by: priyanka | last post by:
Hi there, Can anyone show me how the assert() function works ? I need to develop my own assert() function instead of using the one defined in the assert.h file. It would be great if anyone could...
5
by: Angus | last post by:
Hello I am doing this in a worker thread: char* szPartial = new char; if (szPartial) { lstrcpy(szPartial, szBuffer); PostMessage(m_thishWnd, WM_USER+1, 0, (LPARAM)szPartial); }
1
by: David Bilsby | last post by:
All Apologies for cross posing this but I am not sure if this is a VC 8 STL bug or simply an invalid use of the iterator. I have a PCI card access class which basically abstracts a third party...
12
by: =?Utf-8?B?R2Vvcmdl?= | last post by:
Hello everyone, I saw a couple of form of assert in code on Windows, 1. ASSERT; 2. assert; 3. _ASSERT; 4. _assert.
32
by: bingfeng | last post by:
hello, please see following two code snatches: 1. int foo (const char* some) { assert(some); if (!some) { return -1; //-1 indicates error }
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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,...
0
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...

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.