Skip to content

GitLab

  • Menu
Projects Groups Snippets
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,844
    • Issues 4,844
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 453
    • Merge requests 453
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
    • Value stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #18370

Closed
Open
Created Jun 21, 2020 by Ole@vapourismo

`BlockedIndefinitelyOnMVar` is thrown to non-blocked threads

Summary

BlockedIndefinitelyOnMVar is thrown to other threads that weren't blocked.

Steps to reproduce

-- Test.hs

{-# LANGUAGE TypeApplications #-}

module Main (main) where

import Control.Concurrent
import Control.Exception

main :: IO ()
main = do
  emptyVar <- newEmptyMVar @()
  resultVar <- newEmptyMVar

  _ <- forkIO $ do
    caught <- try @SomeException (readMVar emptyVar)
    putMVar resultVar caught
    print ("thread", caught)

  result <- readMVar resultVar
  print ("main", result)
$ ghc -Wall -Wextra -threaded Test.hs
[1 of 1] Compiling Main             ( Test.hs, Test.o )
Linking Test ...
$ ./Test        
("thread",Left thread blocked indefinitely in an MVar operation)
Test: thread blocked indefinitely in an MVar operation
$ ./Test +RTS -N                     
Test: thread blocked indefinitely in an MVar operation
("thread",Left thread blocked indefinitely in an MVar operation)

It appears the main thread is being thrown a BlockedIndefinitelyOnMVar as well.

This can be decoupled from the empty MVar read:

-- Test.hs

{-# LANGUAGE TypeApplications #-}

module Main (main) where

import Control.Concurrent
import Control.Concurrent.STM
import Control.Exception

main :: IO ()
main = do
  emptyVar <- newEmptyTMVarIO @()
  resultVar <- newEmptyMVar

  _ <- forkIO $ do
    caught <- try @SomeException (atomically (readTMVar emptyVar))
    putMVar resultVar caught
    print ("thread", caught)

  result <- readMVar resultVar
  print ("main", result)
$ ghc -Wall -Wextra -threaded Test.hs
[1 of 1] Compiling Main             ( Test.hs, Test.o )
Linking Test ...
$ ./Test 
("thread",Left thread blocked indefinitely in an STM transaction)
Test: thread blocked indefinitely in an MVar operation
$ ./Test +RTS -N
Test: thread blocked indefinitely in an MVar operation
("thread",Left thread blocked indefinitely in an STM transaction)

Expected behavior

I expect both threads to print the result of try in unspecified order.

 λ ./Test +RTS -N                              
("thread",Left thread blocked indefinitely in an MVar operation)
("main",Left thread blocked indefinitely in an MVar operation)

Environment

  • GHC version used:
    • 8.10.1
    • 8.8.3

Optional:

  • Operating System: NixOS, Linux 5.4.31 x86_64
Edited Jun 21, 2020 by Ole
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking