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

Some examples run at 100% CPU usage #17

Open
nh2 opened this issue Feb 8, 2018 · 3 comments
Open

Some examples run at 100% CPU usage #17

nh2 opened this issue Feb 8, 2018 · 3 comments

Comments

@nh2
Copy link

nh2 commented Feb 8, 2018

E.g. libui-simple-counter-example, 100% CPU in htop

In strace it's busy-looping around poll (because poll() is given a 0-timeout):

[pid 31736] recvmsg(11, 0x7ffe9da1db20, 0) = -1 EAGAIN (Resource temporarily unavailable)
[pid 31736] poll([{fd=11, events=POLLIN}, {fd=12, events=POLLIN}, {fd=13, events=POLLIN}], 3, 0) = 0 (Timeout)
[pid 31736] recvmsg(11, 0x7ffe9da1db20, 0) = -1 EAGAIN (Resource temporarily unavailable)
[pid 31736] poll([{fd=11, events=POLLIN}, {fd=12, events=POLLIN}, {fd=13, events=POLLIN}], 3, 0) = 0 (Timeout)

Not sure if it's an issue with libui or haskell-libuil, or the example code calling the functions wrong.

@nh2
Copy link
Author

nh2 commented Feb 8, 2018

I can confirm the upstream libui tester program as built by make tester doesn't have this problem, it has no CPU usage on idle and no strace output. It passes -1 to poll() for infinite timeout.

@nh2
Copy link
Author

nh2 commented Feb 8, 2018

The fork you use also doesn't have this problem. So it seems to be somewhere in the Haskell code's usage of the library.

@nh2
Copy link
Author

nh2 commented Feb 8, 2018

OK, I was wrong. Not all examples busy loop. READMEExample is fine. It's simply that loops written explicitly in Haskell like this one

whileM_ getHasMain $ do
h <- uiMainStep 0
when (h == 0) $ threadDelay (1000 * 1000 * 16)
busy loop.

@nh2 nh2 changed the title All examples run at 100% CPU usage Some examples run at 100% CPU usage Feb 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant