Re: How to test a program



In article <pan.2009.11.04.12.00.34@xxxxxxxxxxxxxxx>,
arnuld <sunrise@xxxxxxxxxxxxxxx> wrote:
On Tue, 03 Nov 2009 14:04:29 +0100, Pascal J. Bourguignon wrote:

Haven't you heard about multi-core processors?
http://en.wikipedia.org/wiki/Multi-core
.. SNIP...

I don't get If I ask one thread to add an int x = 2; and at the same time
ask another thread to remove it, what will happen, it add/remove half of
it.

If you are very, very lucky the code will crash. If you are unlucky
it will continue on, not giving any indication that there is a problem.

The problem, you see, is that "add an element" is not an atomic operation.
It requires several steps. So does "remove an element". What happens
if these steps are interleaved? Again, if you are really, really lucky
it will throw some sort of exception or otherwise die horribly.

I don't think so, I think it will be added and then removed, as i said,
may be the difference between 2 activities is 10000000th fraction of
second.

This is true until you install the software on a client's machine. At
the point it will die immediately, with extreme prejudice. The machine
probably won't burst into flames, but I wouldn't rule it out.

Alan
--
Defendit numerus
.



Relevant Pages

  • Re: whats wrong with the bitwise operators
    ... left shift or right shift) or using nonnegative signed values ... If the proper stdio.h is implemented as a source file (it ... in which case you're lucky. ... int mainmay be slightly better. ...
    (comp.lang.c)
  • Re: C99 IDE for windows
    ... arnuld said: ... the sign and one for the null terminator. ... To get the number of bits in an int. ... Athlon 64 3000+? ...
    (comp.lang.c)
  • Re: K&R2, exercise 6.4
    ... arnuld said: ... int* pi = arr; ... pointer as result ...
    (comp.lang.c)
  • Re: why is this variable read-only
    ... arnuld said: ... int main ... read only,my question is why?I understand that a and b are locals ... and will be allocated on main's stack frame.Then why can't I modify ...
    (comp.lang.c)
  • Re: EInvalidOp?
    ... int a, b; ... float a, b; ... Undefined behaviour means that you don't ... If nothing happens, you were lucky. ...
    (alt.comp.lang.borland-delphi)