Opened 5 years ago

Closed 5 years ago

#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 Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

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 5 years ago.
7032.patch (2.6 KB) - added by pcapriotti 5 years ago.

Download all attachments as: .zip

Change History (7)

comment:1 Changed 5 years ago by carl

Architecture: Unknown/Multiplex86_64 (amd64)
Operating System: Unknown/MultipleLinux
Type of failure: None/UnknownIncorrect result at runtime

Changed 5 years ago by carl

Attachment: haskell-failed-sleep.hs added

comment:2 Changed 5 years ago by pcapriotti

difficulty: Unknown
Milestone: 7.6.1

Thanks for the report.

comment:3 Changed 5 years ago by igloo

Description: modified (diff)

Changed 5 years ago by pcapriotti

Attachment: 7032.patch added

comment:4 Changed 5 years 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

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 5 years ago by pcapriotti

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.