#7032 closed bug (fixed)

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)

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 (2)

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

Download all attachments as: .zip

Change History (7)

comment:1 Changed 22 months ago by carl

  • Architecture changed from Unknown/Multiple to x86_64 (amd64)
  • Operating System changed from Unknown/Multiple to Linux
  • Type of failure changed from None/Unknown to Incorrect result at runtime

Changed 22 months ago by carl

comment:2 Changed 22 months ago by pcapriotti

  • Difficulty set to Unknown
  • Milestone set to 7.6.1

Thanks for the report.

comment:3 Changed 22 months ago by igloo

  • Description modified (diff)

Changed 22 months ago by pcapriotti

comment:4 Changed 22 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.

comment:5 Changed 22 months ago by pcapriotti

  • Resolution set to fixed
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.