Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: double to string causes divide by zero!



> On Fri, 27 Feb 2004 10:01:37 -0500, "Philip Crotwell"
> <email@hidden> said:
>> Below is a test case that crashes with a divide by zero when appending
>> a double to a string. The code basically looks like this, with 2
>> threads doing it at the same time.
>>
>> double d = some special double String s = ""; s+=d;
>

Does this happen single-threaded?

The reason I asked is because writing to and reading from long and double
values is not atomic.

This means that you can't safely multi-thread; you need to synchronize
access to the 64 bit value. (If the double in question is a local variable
for each thread so you don't get concurrent access then something else may
be going on--threading has nothing to do with it.)

Doug Lea's util.concurrent library (part of JDK 1.5) includes helper
classes for threadsafe access wrappers for long and double.

--kd
_______________________________________________
java-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/java-dev
Do not post admin requests to the list. They will be ignored.


References: 
 >double to string causes divide by zero! (From: Philip Crotwell <email@hidden>)
 >Re: double to string causes divide by zero! (From: "David Risner" <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.