synchronizing MVar ( was compiling concurrent haskell with ghc )
Dennis Sidharta
daniel_jian@yahoo.com
Wed, 30 Jul 2003 18:35:04 -0700 (PDT)
--0-709456096-1059615304=:52379
Content-Type: text/plain; charset=us-ascii
Content-Id:
Content-Disposition: inline
Hi again,
I have tried to play around with MVar today, but
still... I did not see how to synchronize MVar without
the help of forkIO, and then explicitly call yield ::
IO (). But then, if I use forkIO I will create "daemon
threads" that will cause my program to terminates
immediately (back to the original problem).
I attached the source code to this email.
ps: If you can tell the depth of my understanding of
concurrent Haskell from my code, please do not
hesitate to evaluate it (Eg. am I using MVar
correctly? Any better method? etc.), since I am really
new to concurrent Haskell. Thanks.
Again, thank you for the help.
Sincerely,
Dennis Sidharta
--- Sven Panne <Sven.Panne@informatik.uni-muenchen.de>
wrote:
> Dennis Sidharta wrote:
> > [ problems with concurrent Haskell ]
>
> I can see two problems in your code:
>
> * forkIO creates "daemon threads", so the program
> terminates immediately.
>
> * Chan is an unbounded channel, so you won't get a
> "ping pong", which
> is probably what you expected. MVar is your
> friend here.
>
> See
>
http://haskell.org/ghc/docs/latest/html/base/Control.Concurrent.html
>
> Cheers,
> S.
>
>
__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com
--0-709456096-1059615304=:52379
Content-Type: application/octet-stream; name="mySource.hs"
Content-Transfer-Encoding: base64
Content-Description: mySource.hs
Content-Disposition: attachment; filename="mySource.hs"
bW9kdWxlIE1haW4gd2hlcmUNCg0KaW1wb3J0IENvbnRyb2wuQ29uY3VycmVu
dA0KDQptYWluIDo6IElPIFRocmVhZElkDQptYWluID0gZG8gdGhlVGFsayA8
LSBuZXdFbXB0eU1WYXIgOjogSU8gKCBNVmFyIFN0cmluZyApDQogICAgICAg
ICAgZm9ya0lPKCBjaHJpc19wcm9jIHRoZVRhbGsgKQ0KICAgICAgICAgIGZv
cmtJTygga2VsbHlfcHJvYyB0aGVUYWxrICkNCg0Ka2VsbHlfcHJvYyA6OiBN
VmFyIFN0cmluZyAtPiBJTyAoKQ0Ka2VsbHlfcHJvYyB0aGVUYWxrID0gZG8g
dGFsayA8LSB0YWtlTVZhciB0aGVUYWxrDQogICAgICAgICAgICAgICAgICAg
ICAgICBwdXRTdHJMbiB0YWxrDQogICAgICAgICAgICAgICAgICAgICAgICBw
dXRNVmFyIHRoZVRhbGsgIkhlbGxvLCBjYW4gSSBzcGVhayB0byBDaHJpcz8i
DQogICAgICAgICAgICAgICAgICAgICAgICB5aWVsZA0KICAgICAgICAgICAg
ICAgICAgICAgICAgdGFsayA8LSB0YWtlTVZhciB0aGVUYWxrDQogICAgICAg
ICAgICAgICAgICAgICAgICBwdXRTdHJMbiB0YWxrDQogICAgICAgICAgICAg
ICAgICAgICAgICBwdXRNVmFyIHRoZVRhbGsgIkNocmlzLCB0aGlzIGlzIEtl
bGx5IGZyb20gQUNNRSBjb21wYW55XG4gYW5kIHdlIGFyZSBoYXZpbmcgYSBz
cGVjaWFsIG9uLi4uIg0KICAgICAgICAgICAgICAgICAgICAgICAgeWllbGQN
CgkgICAgICAgICAgICAgICAgdGFsayA8LSB0YWtlTVZhciB0aGVUYWxrDQog
ICAgICAgICAgICAgICAgICAgICAgICBwdXRTdHJMbiB0YWxrDQogICAgICAg
ICAgICAgICAgICAgICAgICBwdXRNVmFyIHRoZVRhbGsgIkJ1dCB0aGlzIGlz
IGEgZ3JlYXQgZGVhbCBhbmQgLi4uIg0KICAgICAgICAgICAgICAgICAgICAg
ICAgeWllbGQNCiAJCQl0YWxrIDwtIHRha2VNVmFyIHRoZVRhbGsNCgkJCXB1
dFN0ckxuIHRhbGsgICAgICAgICAgICAgICAgICAgICAgICANCg0KY2hyaXNf
cHJvYyA6OiBNVmFyIFN0cmluZyAtPiBJTyAoKQ0KY2hyaXNfcHJvYyB0aGVU
YWxrID0gZG8gcHV0TVZhciB0aGVUYWxrICJIZWxsbz8iDQogICAgICAgICAg
ICAgICAgICAgICAgICB5aWVsZA0KICAgICAgICAgICAgICAgICAgICAgICAg
dGFsayA8LSB0YWtlTVZhciB0aGVUYWxrDQogICAgICAgICAgICAgICAgICAg
ICAgICBwdXRTdHJMbiB0YWxrDQogICAgICAgICAgICAgICAgICAgICAgICBw
dXRNVmFyIHRoZVRhbGsgIlRoaXMgaXMgQ2hyaXMiDQogICAgICAgICAgICAg
ICAgICAgICAgICB5aWVsZA0KICAgICAgICAgICAgICAgICAgICAgICAgdGFs
ayA8LSB0YWtlTVZhciB0aGVUYWxrDQogICAgICAgICAgICAgICAgICAgICAg
ICBwdXRTdHJMbiB0YWxrDQogICAgICAgICAgICAgICAgICAgICAgICBwdXRN
VmFyIHRoZVRhbGsgIkV4Y3VzZSBtZSwgYnV0IEkgYW0gcmVhbGx5IG5vdCBp
bnRlcmVzdGVkLiINCiAgICAgICAgICAgICAgICAgICAgICAgIHlpZWxkDQog
ICAgICAgICAgICAgICAgICAgICAgICB0YWxrIDwtIHRha2VNVmFyIHRoZVRh
bGsNCiAgICAgICAgICAgICAgICAgICAgICAgIHB1dFN0ckxuIHRhbGsNCiAg
ICAgICAgICAgICAgICAgICAgICAgIHB1dE1WYXIgdGhlVGFsayAiSSBhbSBo
YW5naW5nIHVwIG5vdztcbiBnb29kYnllLiINCgkJICAgICAgICByZXR1cm4g
KCkNCg==
--0-709456096-1059615304=:52379--