Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async undefined behavior #7758

Closed
cheatfate opened this issue May 3, 2018 · 2 comments

Comments

Projects
None yet
2 participants
@cheatfate
Copy link
Member

commented May 3, 2018

This simple code shows undefined behavior inside of asyncdispatch.

Conceptually this code must be completed in 1 poll call, but currently it completes for my PC in debug mode in 2108216, 2110094, 2100304 poll calls.

import asyncdispatch

proc task() {.async.} =
  await sleepAsync(1000)

when isMainModule:
  var counter = 0
  var f = task()
  while not f.finished:
    inc(counter)
    poll()

echo counter

@dom96 dom96 added Stdlib Async labels May 3, 2018

@dom96

This comment has been minimized.

Copy link
Member

commented May 3, 2018

Fun :)

yglukhov added a commit to yglukhov/Nim that referenced this issue May 3, 2018

@dom96

This comment has been minimized.

Copy link
Member

commented May 3, 2018

I don't think this is undefined behaviour, it depends on how fast the CPU executes these poll's.

This will go away once timers are implemented in the event loop.

dom96 added a commit that referenced this issue Jul 5, 2018

Use proper timers in sleepAsync.
Fixes #7886.

Fixes #7758 (remember that `poll` waits for 500ms, change the
             timeout to something like 5s and you'll get
             1 poll call for that code)

Fixes #6929.

Fixes #3909.

dom96 added a commit that referenced this issue Jul 5, 2018

Use proper timers in sleepAsync.
Fixes #7886.

Fixes #7758 (remember that `poll` waits for 500ms, change the
             timeout to something like 5s and you'll get
             1 poll call for that code)

Fixes #6929.

Fixes #3909.

dom96 added a commit that referenced this issue Aug 22, 2018

Don't skip poll() when no handles are present.
Fixes #7886.

Fixes #7758.

Fixes #6929.

Fixes #3909.

Replaces #8209.

@Araq Araq closed this in 7532b37 Aug 23, 2018

dom96 added a commit that referenced this issue Aug 23, 2018

Araq added a commit that referenced this issue Aug 23, 2018

dom96 added a commit that referenced this issue Aug 23, 2018

dom96 added a commit that referenced this issue Aug 24, 2018

Araq added a commit that referenced this issue Aug 25, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.