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
Closed

Async undefined behavior #7758

cheatfate opened this issue May 3, 2018 · 2 comments
Labels
Async Everything related to Nim's async Standard Library

Comments

@cheatfate
Copy link
Member

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 Standard Library Async Everything related to Nim's async labels May 3, 2018
@dom96
Copy link
Contributor

dom96 commented May 3, 2018

Fun :)

yglukhov added a commit to yglukhov/Nim that referenced this issue May 3, 2018
@dom96
Copy link
Contributor

dom96 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
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
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
@Araq Araq closed this as completed in 7532b37 Aug 23, 2018
Araq pushed a commit that referenced this issue Aug 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Async Everything related to Nim's async Standard Library
Projects
None yet
Development

No branches or pull requests

2 participants