Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. Re: Thread Blocking (Eugene Perederey)
2. XML output (Torsten Otto)
3. Re: Error Loading Stdm.lhs in Haskell platform 2012
(Stephen Tetley)
4. Re: Error Loading Stdm.lhs in Haskell platform 2012
(Carlos J. G. Duarte)
5. Re: Thread Blocking (Dean Herington & Elizabeth Lacey)
6. Re: XML output (Manfred Lotz)
----------------------------------------------------------------------
Message: 1
Date: Tue, 4 Sep 2012 12:30:06 -0700
From: Eugene Perederey <[email protected]>
Subject: Re: [Haskell-beginners] Thread Blocking
To: mukesh tiwari <[email protected]>
Cc: [email protected]
Message-ID:
<CAFTqo159L-jcLhCBPREP_Gdq5uCuX7iP1A0OGPaPYftM=ms...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1
Well, not 50/50 but not deterministically -- I've caught
"fun1-main1-fun2" sequence,
"main1-fun1-main2" is much more often.
Since you are using -threaded, the Haskell threads are running on top
of the OS threads, so I guess it depends on the OS scheduler.
On 4 September 2012 12:27, Eugene Perederey <[email protected]> wrote:
> I added a few prints to your code
>
> fun m = do
> putStrLn "fun1"
> putMVar m 10
> putStrLn "fun2"
>
>
> main = do
> m <- newEmptyMVar
> forkIO $ fun m
> putStrLn "main1"
> putMVar m 10
> putStrLn "main2"
>
> It works 50/50 for me in Mac OS X 10.6.8.
>
> On 4 September 2012 12:16, mukesh tiwari <[email protected]> wrote:
>> Hi Eugene
>> Thank you for reply.
>>
>> On Wed, Sep 5, 2012 at 12:32 AM, Eugene Perederey
>> <[email protected]> wrote:
>>>
>>> Why do you think main should block more than once?
>>> I see only two possible scenarios: the fun thread puts to mvar first
>>> thus blocking main,
>>
>>
>> So at least in this case I should get thread blocked indefinitely in an MVar
>> operation
>>
>>>
>>> or 10 is put into mvar in main, blocking the other thread indefinitely.
>>
>>
>> or main will execute and fun thread will die. There are 50 - 50 chance for
>> this ( assuming both are equally likely ). I did some modification in my
>> code and Now I am consistently getting "Concurrent: thread blocked
>> indefinitely in an MVar operation"
>>
>>
>> import Data.List
>> import Control.Concurrent
>>
>> fun m = do
>> putMVar m 10
>> return ()
>>
>>
>> main = do
>> m <- newEmptyMVar
>> forkIO $ fun m
>> putStrLn "I am inside main"
>>
>> putMVar m 10
>> return ()
>>
>> [mukesh.tiwari@ Programming]$ ghc-7.4.1 -threaded -fforce-recomp
>> Concurrent.hs
>> [1 of 1] Compiling Main ( Concurrent.hs, Concurrent.o )
>> Linking Concurrent ...
>> [mukesh.tiwari@ Programming]$ ./Concurrent +RTS -N2
>> I am inside main
>> Concurrent: thread blocked indefinitely in an MVar operation
>>
>> [mukesh.tiwari@ Programming]$ ./Concurrent +RTS -N2
>> I am inside main
>> Concurrent: thread blocked indefinitely in an MVar operation
>>
>> [mukesh.tiwari@ Programming]$ ./Concurrent +RTS -N2
>> I am inside main
>> Concurrent: thread blocked indefinitely in an MVar operation
>>
>> [mukesh.tiwari@ Programming]$ ./Concurrent +RTS -N2
>> I am inside main
>> Concurrent: thread blocked indefinitely in an MVar operation
>>
>> [mukesh.tiwari@ Programming]$ ./Concurrent +RTS -N2
>> I am inside main
>> Concurrent: thread blocked indefinitely in an MVar operation
>>
>> My question is why the outcome in first case is deterministic. Every time
>> the code executing ( at least half the time main thread should be blocked )
>> .
>>
>> Regards
>> Mukesh Tiwari
>>
>>>
>>>
>>> On 4 September 2012 11:54, mukesh tiwari <[email protected]>
>>> wrote:
>>> > Hello All
>>> > I was going trough Real World Haskell and it says "If we try to put a
>>> > value
>>> > into an MVar that is already full, our thread is put to sleep until
>>> > another
>>> > thread takes the value out". I wrote a simple code to block main
>>> >
>>> > import Data.List
>>> > import Control.Concurrent
>>> >
>>> > fun m = do
>>> > putMVar m 10
>>> > return ()
>>> >
>>> >
>>> > main = do
>>> > m <- newEmptyMVar
>>> > forkIO $ fun m
>>> > putMVar m 10
>>> > return ()
>>> >
>>> > What I am expecting that main should be blocked at least couple of times
>>> > but its behaving more deterministically.
>>> > [mukesh.tiwari@ Programming]$ ghc-7.4.1 -threaded -fforce-recomp
>>> > Concurrent.hs
>>> > [1 of 1] Compiling Main ( Concurrent.hs, Concurrent.o )
>>> > Linking Concurrent ...
>>> > [mukesh.tiwari@ Programming]$ ./Concurrent +RTS -N2
>>> > [mukesh.tiwari@ Programming]$ ./Concurrent +RTS -N2
>>> > [mukesh.tiwari@ Programming]$ ./Concurrent +RTS -N2
>>> > [mukesh.tiwari@ Programming]$ ./Concurrent +RTS -N2
>>> > [mukesh.tiwari@ Programming]$ ./Concurrent +RTS -N2
>>> > [mukesh.tiwari@ Programming]$ ./Concurrent +RTS -N2
>>> > [mukesh.tiwari@ Programming]$ ./Concurrent +RTS -N2
>>> > [mukesh.tiwari@ Programming]$ ./Concurrent +RTS -N2
>>> > [mukesh.tiwari@ Programming]$ ./Concurrent +RTS -N2
>>> > [mukesh.tiwari@ Programming]$ ./Concurrent +RTS -N2
>>> > [mukesh.tiwari@ Programming]$ ./Concurrent +RTS -N2
>>> > [mukesh.tiwari@ Programming]$ ./Concurrent +RTS -N2
>>> > [mukesh.tiwari@ Programming]$ ./Concurrent +RTS -N2
>>> > [mukesh.tiwari@ Programming]$ ./Concurrent +RTS -N2
>>> > [mukesh.tiwari@ Programming]$ ./Concurrent +RTS -N2
>>> > [mukesh.tiwari@ Programming]$
>>> >
>>> > I am expecting to get thread blocked indefinitely on MVar at least half
>>> > the
>>> > time. Could some one please tell me why this deterministic behavior ?
>>> > Regards
>>> > Mukesh Tiwari
>>> >
>>> >
>>> > _______________________________________________
>>> > Beginners mailing list
>>> > [email protected]
>>> > http://www.haskell.org/mailman/listinfo/beginners
>>> >
>>>
>>>
>>>
>>> --
>>> Best,
>>> Eugene Perederey
>>
>>
>
>
>
> --
> Best,
> Eugene Perederey
--
Best,
Eugene Perederey
------------------------------
Message: 2
Date: Tue, 04 Sep 2012 22:33:56 +0200
From: "Torsten Otto" <[email protected]>
Subject: [Haskell-beginners] XML output
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"
Hi, all!
I'm struggling with a strange phenomenon.
If I read a file containing
__
a
b
c
__
the program below works as expected. If I read a svg file
__
<?xml version="1.0"?>
<svg xmlns="http://www.w3.org/2000/svg">
<rect x="0" y="0" width="180" height="180" fill="white"/>
</svg>
___
the first two lines are not processed.
Program:
__
module SVG()
where
import IO
main :: IO ()
main = do
s <- readFile "sierpinski1.svg"
putStrLn s
writeFile "sierpinski1_.svg" s
__
Results of putStrLn:
__
*SVG> main
a
b
c
*SVG> main
<rect x="0" y="0" width="180" height="180" fill="white"/>
</svg>
*SVG>
__
File Output lists the whole file, though.
I don't understand this, why is GHCi stripping the output this way?
Thanks,
regards,
Torsten
------------------------------
Message: 3
Date: Tue, 4 Sep 2012 21:36:29 +0100
From: Stephen Tetley <[email protected]>
Subject: Re: [Haskell-beginners] Error Loading Stdm.lhs in Haskell
platform 2012
To: Iwan Awaludin <[email protected]>
Cc: [email protected]
Message-ID:
<cab2tprcqekz8ixqkw+y4rmmm+hzwv0oxbs8j3hvdc60ecap...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1
I think the preferred command line invocation is:
> ghci -XHaskell98
Strangely this seems to be missing in the GHC docs for Flags.
On 4 September 2012 17:40, Stephen Tetley <[email protected]> wrote:
> I can't find the exact command to use in the GHC docs to enable H98,
> but you could try the following old flag which disables GHCs
> extensions:
>
>> ghci -fno-glasgow-exts
------------------------------
Message: 4
Date: Tue, 04 Sep 2012 21:58:38 +0100
From: "Carlos J. G. Duarte" <[email protected]>
Subject: Re: [Haskell-beginners] Error Loading Stdm.lhs in Haskell
platform 2012
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
On 09/04/12 21:36, Stephen Tetley wrote:
> I think the preferred command line invocation is:
>
>> ghci -XHaskell98
This also works: ghc -XNPlusKPatterns
------------------------------
Message: 5
Date: Tue, 4 Sep 2012 23:12:58 -0400
From: Dean Herington & Elizabeth Lacey <[email protected]>
Subject: Re: [Haskell-beginners] Thread Blocking
To: mukesh tiwari <[email protected]>, Eugene Perederey
<[email protected]>
Cc: [email protected]
Message-ID: <a06240801cc6c711cf2f0@[10.0.1.6]>
Content-Type: text/plain; charset="us-ascii"; Format="flowed"
There's no basis on which to assume both alternative schedules are
equally likely. I would guess that, in your first example, there's
enough start-up cost for a new thread that the main thread
consistently gets to its putMVar first, whereas in the second
example, main is waylaid with its putStrLn, allowing the forked
thread to get there first consistently.
Dean
At 12:46 AM +0530 9/5/12, mukesh tiwari wrote:
>Hi Eugene
>Thank you for reply.
>
>On Wed, Sep 5, 2012 at 12:32 AM, Eugene Perederey
><<mailto:[email protected]>[email protected]>
>wrote:
>
>Why do you think main should block more than once?
>I see only two possible scenarios: the fun thread puts to mvar first
>thus blocking main,
>
>
>So at least in this case I should get thread blocked indefinitely in
>an MVar operation
>
>
>or 10 is put into mvar in main, blocking the other thread indefinitely.
>
>
>or main will execute and fun thread will die. There are 50 - 50
>chance for this ( assuming both are equally likely ). I did some
>modification in my code and Now I am consistently getting
>"Concurrent: thread blocked indefinitely in an MVar operation"
>
>import Data.List
>import Control.Concurrent
>
>fun m = do
> putMVar m 10
> return ()
>
>
>main = do
> m <- newEmptyMVar
> forkIO $ fun m
> putStrLn "I am inside main"
> putMVar m 10
> return ()
>
>[mukesh.tiwari@ Programming]$ ghc-7.4.1 -threaded -fforce-recomp
>Concurrent.hs
>[1 of 1] Compiling Main ( Concurrent.hs, Concurrent.o )
>Linking Concurrent ...
>[mukesh.tiwari@ Programming]$ ./Concurrent +RTS -N2
>I am inside main
>Concurrent: thread blocked indefinitely in an MVar operation
>[mukesh.tiwari@ Programming]$ ./Concurrent +RTS -N2
>I am inside main
>Concurrent: thread blocked indefinitely in an MVar operation
>[mukesh.tiwari@ Programming]$ ./Concurrent +RTS -N2
>I am inside main
>Concurrent: thread blocked indefinitely in an MVar operation
>[mukesh.tiwari@ Programming]$ ./Concurrent +RTS -N2
>I am inside main
>Concurrent: thread blocked indefinitely in an MVar operation
>[mukesh.tiwari@ Programming]$ ./Concurrent +RTS -N2
>I am inside main
>Concurrent: thread blocked indefinitely in an MVar operation
>
>My question is why the outcome in first case is deterministic. Every
>time the code executing ( at least half the time main thread should
>be blocked ) .
>
>Regards
>Mukesh Tiwari
>
>
>
>On 4 September 2012 11:54, mukesh tiwari
><<mailto:[email protected]>[email protected]>
>wrote:
>> Hello All
>> I was going trough Real World Haskell and it says "If we try to put a value
>> into an MVar that is already full, our thread is put to sleep until another
>> thread takes the value out". I wrote a simple code to block main
>>
>> import Data.List
>> import Control.Concurrent
>>
>> fun m = do
>> putMVar m 10
>> return ()
>>
>>
>> main = do
>> m <- newEmptyMVar
>> forkIO $ fun m
>> putMVar m 10
>> return ()
>>
>> What I am expecting that main should be blocked at least couple of times
>> but its behaving more deterministically.
>> [mukesh.tiwari@ Programming]$ ghc-7.4.1 -threaded -fforce-recomp
>> Concurrent.hs
>> [1 of 1] Compiling Main ( Concurrent.hs, Concurrent.o )
>> Linking Concurrent ...
>> [mukesh.tiwari@ Programming]$ ./Concurrent +RTS -N2
>> [mukesh.tiwari@ Programming]$ ./Concurrent +RTS -N2
>> [mukesh.tiwari@ Programming]$ ./Concurrent +RTS -N2
>> [mukesh.tiwari@ Programming]$ ./Concurrent +RTS -N2
>> [mukesh.tiwari@ Programming]$ ./Concurrent +RTS -N2
>> [mukesh.tiwari@ Programming]$ ./Concurrent +RTS -N2
>> [mukesh.tiwari@ Programming]$ ./Concurrent +RTS -N2
>> [mukesh.tiwari@ Programming]$ ./Concurrent +RTS -N2
>> [mukesh.tiwari@ Programming]$ ./Concurrent +RTS -N2
>> [mukesh.tiwari@ Programming]$ ./Concurrent +RTS -N2
>> [mukesh.tiwari@ Programming]$ ./Concurrent +RTS -N2
>> [mukesh.tiwari@ Programming]$ ./Concurrent +RTS -N2
>> [mukesh.tiwari@ Programming]$ ./Concurrent +RTS -N2
> > [mukesh.tiwari@ Programming]$ ./Concurrent +RTS -N2
>> [mukesh.tiwari@ Programming]$ ./Concurrent +RTS -N2
>> [mukesh.tiwari@ Programming]$
>>
>> I am expecting to get thread blocked indefinitely on MVar at least half the
>> time. Could some one please tell me why this deterministic behavior ?
>> Regards
>> Mukesh Tiwari
>>
>>
>
> > _______________________________________________
>> Beginners mailing list
>> <mailto:[email protected]>[email protected]
>>
>><http://www.haskell.org/mailman/listinfo/beginners>http://www.haskell.org/mailman/listinfo/beginners
>>
>
>
>
>--
>Best,
>Eugene Perederey
>
>
>
>_______________________________________________
>Beginners mailing list
>[email protected]
>http://www.haskell.org/mailman/listinfo/beginners
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20120904/4f06f1df/attachment-0001.htm>
------------------------------
Message: 6
Date: Wed, 5 Sep 2012 06:34:36 +0200
From: Manfred Lotz <[email protected]>
Subject: Re: [Haskell-beginners] XML output
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=US-ASCII
On Tue, 04 Sep 2012 22:33:56 +0200
"Torsten Otto" <[email protected]> wrote:
> Hi, all!
>
> I'm struggling with a strange phenomenon.
> If I read a file containing
>
> __
> a
> b
> c
> __
>
> the program below works as expected. If I read a svg file
> __
> <?xml version="1.0"?>
> <svg xmlns="http://www.w3.org/2000/svg">
> <rect x="0" y="0" width="180" height="180" fill="white"/>
> </svg>
> ___
> the first two lines are not processed.
>
> Program:
> __
> module SVG()
> where
>
> import IO
>
> main :: IO ()
> main = do
> s <- readFile "sierpinski1.svg"
> putStrLn s
> writeFile "sierpinski1_.svg" s
> __
>
> Results of putStrLn:
> __
> *SVG> main
> a
> b
> c
> *SVG> main
> <rect x="0" y="0" width="180" height="180" fill="white"/>
> </svg>
> *SVG>
> __
>
> File Output lists the whole file, though.
>
> I don't understand this, why is GHCi stripping the output this way?
>
> Thanks,
> regards,
> Torsten
>
I got a compile error, and had to change
import IO
to
import System.IO
Then it worked fine, i.e. all lines of were printed to stdout as well as
written to the output file.
What is you ghci version?
--
Manfred
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 51, Issue 8
****************************************