[Haskell-cafe] killing a running thread interactively

Simon Marlow simonmar at microsoft.com
Fri Sep 23 08:08:54 EDT 2005


Haskell doesn't, but the compilers all support a kind of global mutable
variable.  See various lengthy discussions on the topic on this list and
the Haskell list in the past.  Briefly, you do it like this:

{-# NOILINE var #-}
var :: IORef [ThreadId]
var = unsafePerformIO (newIORef [])

and if you're using GHC, compile the module with -fno-cse.

Cheers,
	Simon

On 22 September 2005 17:58, S. Alexander Jacobson wrote:

> Ok, I didn't think Haskell had mutable global variables.
> How would this work?
> 
> -ALex-
> 
> On Thu, 22 Sep 2005, Simon Marlow wrote:
> 
>> There's no getAllThreadIds or similar right now.  You have to save
>> the ThreadIds yourself, perhaps in a global variable.  Writing to a
>> file doesn't work because there's no instance Read ThreadId.
>> 
>> Cheers,
>> 	Simon
>> 
>> On 21 September 2005 21:14, S. Alexander Jacobson wrote:
>> 
>>> More particularly, is there a getAllThreadIds function somewhere?
>>> 
>>> -Ale-
>>> 
>>> On Wed, 21 Sep 2005, S. Alexander Jacobson wrote:
>>> 
>>>> Is the general pattern to write all threadIds to a file, and then
>>>> have a separate function that takes the file and kills them?
>>>> 
>>>> Or is there something more clever?
>>>> 
>>>> -Alex-
>>>> 
>>>> On Wed, 21 Sep 2005, Simon Marlow wrote:
>>>> 
>>>>> On 16 September 2005 20:42, S. Alexander Jacobson wrote:
>>>>> 
>>>>>> If I am running a server interactively. (using ghci).
>>>>>> Is there any way to kill its running threads without terminating
>>>>>> the interpreter?
>>>>> 
>>>>> If you can get ThreadIds for the threads, yes.  GHCi doesn't
>>>>> (currently) create a new thread for each expression evaluation, so
>>>>> attempting to kill that thread might kill your GHCi session (it
>>>>> shouldn't but that's another story).
>>>>> 
>>>>> Cheers,
>>>>> 	Simon
>>>>> 
>>>>> ** CRM114 Whitelisted by: simonmar at microsoft.com **
>>>>> 
>>>> 
>>>> ______________________________________________________________
>>>> S. Alexander Jacobson tel:917-770-6565 http://alexjacobson.com
>>>> 
>>> 
>>> ______________________________________________________________
>>> S. Alexander Jacobson tel:917-770-6565 http://alexjacobson.com
>> 
>> ** CRM114 Whitelisted by: simonmar at microsoft.com **
>> 
> 
> ______________________________________________________________
> S. Alexander Jacobson tel:917-770-6565 http://alexjacobson.com



More information about the Haskell-Cafe mailing list