[concurrency-interest] deadline and long overflow

Peter Veentjer alarmnummer at gmail.com
Wed Apr 20 09:57:43 EDT 2016


Thanks for the replies.

The question is not about waiting given amount of time; but the calculation
of the deadline itself which can become negative due to overflow. So
imagine you call:

queue.poll(Long.MAX_VALUE, NANOS)

then the deadline will be < 0 due to overflow.

The question is if it can happen that a blocking call fails with a timeout,
perhaps immediately due to this deadline becoming negative. I made some
small examples and it seems to self correct like David suggested but it
feels a bit funny.



On Wed, Apr 20, 2016 at 3:52 PM, Doug Lea <dl at cs.oswego.edu> wrote:

> On 04/20/2016 06:32 AM, Alex Otenko wrote:
>
>> Wouldn’t that be a deadline of 500-odd years?
>>
>
> Overflow issues can occur in half that time though (around 292 years).
>
>
>> Technically, overflow is a possibility. Practically - very unlikely.
>>
>>
> Right. There is a disclaimer about this in System.nanotime:
> http://docs.oracle.com/javase/8/docs/api/java/lang/System.html#nanoTime--
>
> This could be repeated in every timing-related method, but isn't.
>
> -Doug
>
> Alex
>>
>> On 20 Apr 2016, at 11:05, Peter Veentjer <alarmnummer at gmail.com
>>> <mailto:alarmnummer at gmail.com>> wrote:
>>>
>>> I have a question regarding dealing with deadlines and long overflow.
>>>
>>> For example the following from the SynchronousQueue:
>>>
>>> final long deadline = timed ? System.nanoTime() + nanos :0L;
>>> What would happen if someone calls queue.offer(item, Long.MAX_VALUE,
>>> NANOS)
>>> then deadline overflows and becomes negative. I see the same approach in
>>> other
>>> parts e.g.
>>>
>>> this.deadline = timed ? System.nanoTime() + nanos :0L;
>>> from the Phaser. Personally I like the simplicity; but my concern is
>>> regarding
>>> validity.
>>> _______________________________________________
>>> Concurrency-interest mailing list
>>> Concurrency-interest at cs.oswego.edu <mailto:
>>> Concurrency-interest at cs.oswego.edu>
>>> http://cs.oswego.edu/mailman/listinfo/concurrency-interest
>>>
>>
>>
>>
>> _______________________________________________
>> Concurrency-interest mailing list
>> Concurrency-interest at cs.oswego.edu
>> http://cs.oswego.edu/mailman/listinfo/concurrency-interest
>>
>>
>
>
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at cs.oswego.edu
> http://cs.oswego.edu/mailman/listinfo/concurrency-interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20160420/a88c9eb9/attachment.html>


More information about the Concurrency-interest mailing list