summaryrefslogtreecommitdiff
path: root/libraries/base/Control/Concurrent.hs
Commit message (Collapse)AuthorAgeFilesLines
* fdReady: Use C99 bools / CBool in signatureNiklas Hambüchen2017-12-111-7/+7
| | | | | | | | | | Reviewers: bgamari, Phyx, austin, hvr, simonmar Reviewed By: bgamari Subscribers: syd, rwbarton, thomie Differential Revision: https://phabricator.haskell.org/D4041
* base: fdReady(): Fix timeouts > ~49 days overflowing. Fixes #14262.Niklas Hambüchen2017-11-241-5/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | On 64-bit UNIX and Windows, Haskell `Int` has 64 bits but C `int msecs` has 32 bits, resulting in an overflow. This commit fixes it by switching fdReady() to take int64_t, into which a Haskell `Int` will always fit. (Note we could not switch to `long long` because that is 32 bit on 64-bit Windows machines.) Further, to be able to actually wait longer than ~49 days, we put loops around the waiting syscalls (they all accept only 32-bit integers). Note the timer signal would typically interrupt the syscalls before the ~49 days are over, but you can run Haskell programs without the timer signal, an we want it to be correct in all cases. Reviewers: bgamari, austin, hvr, NicolasT, Phyx Reviewed By: bgamari, Phyx Subscribers: syd, Phyx, rwbarton, thomie GHC Trac Issues: #14262 Differential Revision: https://phabricator.haskell.org/D4011
* Prefer #if defined to #ifdefBen Gamari2017-04-281-6/+6
| | | | Our new CPP linter enforces this.
* Change catch# demand signatureDavid Feuer2017-03-011-1/+1
| | | | | | | | | | | | | | | | | | * Give `catch#` a lazy demand signature, to make it more honest. * Make `catchException` and `catchAny` force their arguments so they actually behave as advertised. * Use `catch` rather than `catchException` in `forkIO`, `forkOn`, and `forkOS` to avoid losing exceptions. Fixes #13330 Reviewers: rwbarton, simonpj, simonmar, bgamari, hvr, austin Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D3244
* Use catchException in a few more placesBen Gamari2016-03-111-3/+3
| | | | | | | | | | | | | | These are cases in the standard library that may benefit from the strictness signature of catchException and where we know that the action won't bottom. Test Plan: Validate, carefully consider changed callsites Reviewers: austin, hvr Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D1972
* Using unsafe foreign import for rtsSupportsBoundThreads (part of #9696)Marcin Mrotek2016-03-051-1/+1
| | | | | | | | | | | | | | | | | | A safe import is unnecessary considering rtsSupportsBoundThreads simply returns a constant. This commit doesn't fix the main issue of ticket #9696 that "readRawBufferPtr and writeRawBufferPtr allocate memory". Reviewers: bgamari, austin, hvr Reviewed By: hvr Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D1964 GHC Trac Issues: #9696
* Allow CallStacks to be frozenEric Seidel2015-12-231-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This introduces "freezing," an operation which prevents further locations from being appended to a CallStack. Library authors may want to prevent CallStacks from exposing implementation details, as a matter of hygiene. For example, in ``` head [] = error "head: empty list" ghci> head [] *** Exception: head: empty list CallStack (from implicit params): error, called at ... ``` including the call-site of `error` in `head` is not strictly necessary as the error message already specifies clearly where the error came from. So we add a function `freezeCallStack` that wraps an existing CallStack, preventing further call-sites from being pushed onto it. In other words, ``` pushCallStack callSite (freezeCallStack callStack) = freezeCallStack callStack ``` Now we can define `head` to not produce a CallStack at all ``` head [] = let ?callStack = freezeCallStack emptyCallStack in error "head: empty list" ghci> head [] *** Exception: head: empty list CallStack (from implicit params): error, called at ... ``` --- 1. We add the `freezeCallStack` and `emptyCallStack` and update the definition of `CallStack` to support this functionality. 2. We add `errorWithoutStackTrace`, a variant of `error` that does not produce a stack trace, using this feature. I think this is a sensible wrapper function to provide in case users want it. 3. We replace uses of `error` in base with `errorWithoutStackTrace`. The rationale is that base does not export any functions that use CallStacks (except for `error` and `undefined`) so there's no way for the stack traces (from Implicit CallStacks) to include user-defined functions. They'll only contain the call to `error` itself. As base already has a good habit of providing useful error messages that name the triggering function, the stack trace really just adds noise to the error. (I don't have a strong opinion on whether we should include this third commit, but the change was very mechanical so I thought I'd include it anyway in case there's interest) 4. Updates tests in `array` and `stm` submodules Test Plan: ./validate, new test is T11049 Reviewers: simonpj, nomeata, goldfire, austin, hvr, bgamari Reviewed By: simonpj Subscribers: thomie Projects: #ghc Differential Revision: https://phabricator.haskell.org/D1628 GHC Trac Issues: #11049
* Start using `-W` instead of `-f(no-)warn` in some placesHerbert Valerio Riedel2015-12-161-1/+1
| | | | | | | | | | | | | | | | | | This replaces some occurences of `-f(no-)warn` with the new `-W`-aliases introduced via 2206fa8cdb120932 / #11218, in cases which are guaranteed to be invoked with recent enough GHC (i.e. the stage1+ GHC). After this commit, mostly the compiler and the testsuite remain using `-f(wo-)warn...` because the compiler needs to be bootstrappable with older GHCs, while for the testsuite it's convenient to be able to quickly compare the behavior to older GHCs (which may not support the new flags yet). The compiler-part can be updated to use the new flags once GHC 8.3 development starts. Reviewed By: quchen Differential Revision: https://phabricator.haskell.org/D1637
* base: Add forkOSWithUnmaskJoey Adams2015-10-131-1/+8
| | | | | | | | | | Fixes #8010, according to the specified libraries proposal. [1] Also, some minor wordsmithing. [1] http://thread.gmane.org/gmane.comp.lang.haskell.libraries/22709 Signed-off-by: Austin Seipp <austin@well-typed.com>
* Convert `/Since: .../` to new `@since ...` syntaxHerbert Valerio Riedel2014-12-161-3/+3
| | | | | | Starting with Haddock 2.16 there's a new built-in support for since-annotations Note: This exposes a bug in the `@since` implementation (see e.g. `Data.Bits`)
* Refactor module imports in baseHerbert Valerio Riedel2014-10-191-4/+3
| | | | | | | | | | This commit removes a couple of {-# OPTIONS_GHC -fno-warn-unused-imports #-} by cleaning up the imports, as well as ensuring that all modules in the GHC.* hierarchy avoid importing the `Prelude` module to clean-up the import graph a bit.
* Remove redundant explicit `Prelude` importsHerbert Valerio Riedel2014-10-191-2/+0
| | | | Since they're implied by the lack of `NoImplicitPrelude`
* Fix potential `mingw32_HOST_OS` breakage from eae19112462fe77Herbert Valerio Riedel2014-09-201-1/+1
|
* Move `when` to GHC.BaseHerbert Valerio Riedel2014-09-181-1/+0
| | | | | | | | | This allows several modules to avoid importing Control.Monad and thus break import cycles that manifest themselves when implementing #9586 Reviewed By: austin, ekmett Differential Revision: https://phabricator.haskell.org/D222
* Fix typos in base documentation.Shachaf Ben-Kiki2014-07-101-2/+2
| | | | | | | | | | | | | | Summary: Signed-off-by: Shachaf Ben-Kiki <shachaf@gmail.com> Test Plan: n/a Reviewers: austin Reviewed By: austin Subscribers: simonmar, relrod, carter Differential Revision: https://phabricator.haskell.org/D57
* Drop redundant `{-# LANGUAGE #-}` pragmasHerbert Valerio Riedel2013-09-281-1/+0
| | | | | | | | | | | | | This removes language pragmas from Haskell modules which are implicitly active with `default-language: Haskell2010`. Specifically, the following language extension pragmas are removed by this commit: - PatternGuards - ForeignFunctionInterface - EmptyDataDecls - NoBangPatterns Signed-off-by: Herbert Valerio Riedel <hvr@gnu.org>
* Add Haddock `/Since: 4.6.0.0/` comments to symbolsHerbert Valerio Riedel2013-09-211-0/+1
| | | | | | | | | | This commit retroactively adds `/Since: 4.6.0.0/` annotations to symbols newly added/exposed in `base-4.6.0.0` (as shipped with GHC 7.6.1). See also 6368362f which adds the respective annotation for symbols newly added in `base-4.7.0.0` (that goes together with GHC 7.8.1). Signed-off-by: Herbert Valerio Riedel <hvr@gnu.org>
* Add Haddock `/Since: 4.7.0.0/` comments to new symbolsHerbert Valerio Riedel2013-09-211-0/+4
| | | | | | | | | | | | | | | | | | These annotations were added in such a way, that the line {{{ /Since: 4.7.0.0/ }}} represents the last paragraph of the Haddock comment. Maybe Haddock will have support for this meta-syntax at some point, and be able to inherited the since-version property to the children of an annotated symbol and display the since-version property in the rendered documentation only in cases when it's not visually obvious (for instance, when re-exporting documentation strings). Signed-off-by: Herbert Valerio Riedel <hvr@gnu.org>
* Follow changes in comparison primops (see #6135)Jan Stolarek2013-09-181-1/+1
|
* Trailing whitespacesJan Stolarek2013-09-181-9/+9
|
* Constant-fold `__GLASGOW_HASKELL__` CPP conditionalsHerbert Valerio Riedel2013-09-171-15/+0
| | | | | | | | | | Now that HUGS and NHC specific code has been removed, this commit "folds" the now redundant `#if((n)def)`s containing `__GLASGOW_HASKELL__`. This renders `base` officially GHC only. This commit also removes redundant `{-# LANGUAGE CPP #-}`. Signed-off-by: Herbert Valerio Riedel <hvr@gnu.org>
* Remove Hugs98 specific codeHerbert Valerio Riedel2013-09-171-10/+0
| | | | | | | For rationale. see http://permalink.gmane.org/gmane.comp.lang.haskell.ghc.devel/2349 Signed-off-by: Herbert Valerio Riedel <hvr@gnu.org>
* Add a section of documentation about the interaction of threads and finalizersSimon Marlow2013-07-021-0/+32
|
* Remove some things deprecated since GHC 7.2Ian Lynagh2013-02-161-3/+0
| | | | | 7.2 is too old even to build HEAD, so seems reasonable to remove them now.
* Fix warnings on WindowsIan Lynagh2013-01-121-5/+5
|
* Fix ambiguity error on WindowsIan Lynagh2013-01-121-2/+2
| | | | I assume that we only want to catch IOExceptions, as withThread does.
* Expose new threadWaitSTM functions in Control.Concurrent (see #7216).Andreas Voellmy2013-01-121-1/+49
| | | | Supports threadWaitReadSTM and threadWaitWriteSTM on Windows with the threaded runtime system.
* Add back new working QSem and QSemN implementations (#7417)Simon Marlow2012-12-101-0/+4
| | | | | | | | | We decided not to break existing users without providing an easy migration path. For the time being I've made these implementations, which fix the bugs in the old versions and perform reasonably well. In due course we should move the concurrency functionality, including these modules, out of base and into a separate package.
* Remove commented types in module export listsIan Lynagh2012-10-271-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | These comments are rather less useful now that haddock can give docs with the same informatino in the module synopsis. Having to maintain them when making changes to the library is a pain, and when people forget about doing so there is nothing that checks that the comments are right, so mistakes tend to linger. Of the comments that my script detected, 78 of 684 were already incorrect in one way or another, e.g. missing context: Text.Show.showsPrec Comment type: Int -> a -> ShowS Actual type: Show a => Int -> a -> ShowS wrong context: Numeric.readInt Comment type: Integral a => a -> (Char -> Bool) -> (Char -> Int) -> ReadS a Actual type: Num a => a -> (Char -> Bool) -> (Char -> Int) -> ReadS a not following a class change (e.g. Num losing its Eq superclass): Text.Read.Lex.readOctP Comment type: Num a => ReadP a Actual type: (Eq a, Num a) => ReadP a not following the Exceptions change: GHC.Conc.childHandler Comment type: Exception -> IO () Actual type: SomeException -> IO () or just always been wrong: GHC.Stable.deRefStablePtr Comment type: StablePtr a -> a Actual type: StablePtr a -> IO a
* Remove some deprecated modules and functionsIan Lynagh2012-07-201-92/+0
|
* Deprecate Control.Concurrent.{QSem,QSemNSampleVar}Ian Lynagh2012-06-231-0/+5
| | | | Also Control.Concurrent.{mergeIO,nmergeIO}, which use those modules.
* add forkFinallySimon Marlow2012-06-071-4/+23
| | | | | | | | | | | | This is a more robust version of "forkIO (m `finally` k)", because it closes a window between thread creation and the finally where the thread can receive an async exception. Useful for layers over threads that need to catch threads dying with absolute certainty. forkFinally :: IO a -> (Either SomeException a -> IO ()) -> IO ThreadId forkFinally action and_then = mask $ \restore -> forkIO $ try (restore action) >>= and_then
* move mkWeakThreadId to GHC.Conc.Sync; export it from Control.ConcurrentSimon Marlow2012-04-121-0/+3
|
* Export setNumCapabilitiesSimon Marlow2012-01-031-0/+1
| | | | | I hadn't noticed that we already have getNumCapabilities here, so we should also have setNumCapabilities.
* Export constructors for Foreign.C.Types and System.Posix.Types newtypesIan Lynagh2011-10-211-1/+1
| | | | | Part of trac #5529. We also now import the constructors in various modules that use them in FFI decls.
* update IO manager documentation (#5547)Simon Marlow2011-10-181-1/+2
|
* SafeHaskell: Added SafeHaskell to baseDavid Terei2011-06-181-0/+1
|
* Export the affinity API from Control.Concurrent: forkOn and friends.Simon Marlow2011-03-301-0/+6
| | | | | | | | | | | | | | | | | forkOn :: Int -> IO () -> IO ThreadId forkOnWithUnmask :: Int -> ((forall a . IO a -> IO a) -> IO ()) -> IO ThreadId getNumCapabilities :: IO Int threadCapability :: ThreadId -> IO (Int, Bool) Following discussion on the libraries list, I renamed forkOnIO to forkOn. In due course we might want to also rename forkIO to fork. I left the Int argument as it is, it's quite useful to be able to specify a number to be interpreted modulo the actual number of processors. I also used the term "capability" consistently. It might not be the best choice, but we have to pick something.
* add forkIOWithUnmask, forkOnIOWithUnmask; deprecate forkIOUnmaskedSimon Marlow2011-03-291-4/+7
| | | | | | | | | With forkIOUnmasked it wasn't possible to reliably set up an exception handler in the child thread, because exceptions were immediately unmasked. forkIOWithUnmask :: ((forall a . IO a -> IO a) -> IO ()) -> IO ThreadId forkOnIOWithUnmask :: Int -> ((forall a . IO a -> IO a) -> IO ()) -> IO ThreadId
* Use explicit language extensions & remove extension fields from base.cabalsimonpj@microsoft.com2011-01-281-0/+7
| | | | | | | | | | Add explicit {-# LANGUAGE xxx #-} pragmas to each module, that say what extensions that module uses. This makes it clearer where different extensions are used in the (large, variagated) base package. Now base.cabal doesn't need any extensions field Thanks to Bas van Dijk for doing all the work.
* Drop closeFd from Control.Concurrent, rename to closeFdWithBryan O'Sullivan2010-12-061-21/+6
|
* Fix #4514 - IO manager deadlockBryan O'Sullivan2010-11-261-0/+25
| | | | | | | | | | | | | | | * The public APIs for threadWaitRead and threadWaitWrite remain unchanged, and now throw an IOError if a file descriptor is closed behind their backs. This behaviour is documented. * The GHC.Conc API is extended to add a closeFd function, the behaviour of which is documented. * Behind the scenes, we add a new evtClose event, which is used only when one thread closes a file descriptor that other threads are blocking on. * Both base's IO code and network use the new closeFd function.
* Remove redundant fromIntegralsimonpj@microsoft.com2010-11-171-1/+1
|
* Catch exceptions in current thread and throw them to the forked thread in ↵Bas van Dijk2010-10-141-8/+14
| | | | runInUnboundThread
* There's no need to explicitly check for blocked status in runInUnboundThread ↵Bas van Dijk2010-10-141-3/+1
| | | | when we have mask
* Use throwIO instead of throw in runInBoundThread and runInUnboundThreadBas van Dijk2010-10-141-10/+7
|
* New asynchronous exception control API (base parts)Simon Marlow2010-07-081-10/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | As discussed on the libraries/haskell-cafe mailing lists http://www.haskell.org/pipermail/libraries/2010-April/013420.html This is a replacement for block/unblock in the asychronous exceptions API to fix a problem whereby a function could unblock asynchronous exceptions even if called within a blocked context. The new terminology is "mask" rather than "block" (to avoid confusion due to overloaded meanings of the latter). The following is the new API; the old API is deprecated but still available for the time being. Control.Exception ----------------- mask :: ((forall a. IO a -> IO a) -> IO b) -> IO b mask_ :: IO a -> IO a uninterruptibleMask :: ((forall a. IO a -> IO a) -> IO b) -> IO b uninterruptibleMask_ :: IO a -> IO getMaskingState :: IO MaskingState data MaskingState = Unmasked | MaskedInterruptible | MaskedUninterruptible Control.Concurrent ------------------ forkIOUnmasked :: IO () -> IO ThreadId
* withThread: block asynchronous exceptions before installing exception handler.Bas van Dijk2010-03-291-1/+1
| | | | | | Note that I don't unblock the given io computation. Because AFAICS withThread is only called with 'waitFd' which only performs an FFI call which can't receive asynchronous exceptions anyway.
* runInUnboundThread: block asynchronous exceptions before installing ↵Bas van Dijk2010-03-291-1/+4
| | | | exception handler
* Fix build on WindowsIan Lynagh2009-07-111-4/+4
|