Ticket #7032 (closed bug: fixed)

Opened 11 months ago

Last modified 11 months ago

sleep fails for compiled program

Reported by: carl Owned by:
Priority: normal Milestone: 7.6.1
Component: Compiler Version: 7.4.2
Keywords: Cc:
Operating System: Linux Architecture: x86_64 (amd64)
Type of failure: Incorrect result at runtime Difficulty: Unknown
Test Case: Blocked By:
Blocking: Related Tickets:

Description (last modified by igloo) (diff)

For the following program, runghc or ghci produces a list of numbers with a delay between printing each number. But when I run the compiled program, there is no delay.

import System.Posix
main = loop 10
loop 0 = print "done"
loop n = do
  print n
  sleep 3
  loop $ n - 1

Attachments

haskell-failed-sleep.hs Download (110 bytes) - added by carl 11 months ago.
7032.patch Download (2.6 KB) - added by pcapriotti 11 months ago.

Change History

Changed 11 months ago by carl

  • failure changed from None/Unknown to Incorrect result at runtime
  • os changed from Unknown/Multiple to Linux
  • architecture changed from Unknown/Multiple to x86_64 (amd64)

Changed 11 months ago by carl

Changed 11 months ago by pcapriotti

  • difficulty set to Unknown
  • milestone set to 7.6.1

Thanks for the report.

Changed 11 months ago by igloo

  • description modified (diff)

Changed 11 months ago by pcapriotti

Changed 11 months ago by pcapriotti

According to the man page of sleep:

sleep() makes the calling thread sleep until seconds
seconds have elapsed or a signal arrives which is not
ignored.

Since we use SIGVTALRM for the RTS clock, sleep is always going to be interrupted immediately. Normally, you should use threadDelay, which will also let other threads run (even without -threaded).

The attached patch explains this problem in the documentation for sleep, and adds a WARNING pragma.

Changed 11 months ago by pcapriotti

  • status changed from new to closed
  • resolution set to fixed

Pushed patch as ba7961f118f42ba9db7e5fba017270a257852ff3.

Note: See TracTickets for help on using tickets.