Haskell for Imperative Programmers #28 - Concurrency & Threads

แชร์
ฝัง
  • เผยแพร่เมื่อ 4 ต.ค. 2024

ความคิดเห็น • 21

  • @adamtafesse8971
    @adamtafesse8971 4 ปีที่แล้ว +7

    I am only half way through but I just wanted to say video is a great resource! Clear and concise!

  • @DazzlePirate
    @DazzlePirate 4 ปีที่แล้ว +9

    Loving this series!

  • @nadaxiong
    @nadaxiong 4 ปีที่แล้ว +5

    Very clear explanations! Love it!

  • @LeoOno
    @LeoOno 4 ปีที่แล้ว +6

    Thanks for these series, they are helping me a lot :) !

  • @yoshieatspizzad913
    @yoshieatspizzad913 2 ปีที่แล้ว +2

    for some reason i find the "show tid" at 11:00 incredibly funny

  • @rifaldhiaw
    @rifaldhiaw 4 ปีที่แล้ว +3

    Yeeaa... Finally more expert content.
    Thank you and please keep it up

  • @moisesbr
    @moisesbr 2 ปีที่แล้ว

    Wow, excellent lesson. Most concurrency gotchas in less than half an hour!

  • @rodrigo_botti
    @rodrigo_botti 4 ปีที่แล้ว +1

    Awesome video!
    I'd like to add something: using finally to release the lock on the mutex.
    --
    takeMVar mutex
    finally (putStrLn greeting) (putMVar mutex ())
    --

  • @MasthaX
    @MasthaX 3 ปีที่แล้ว +1

    This video is very helpful and well explained. They demonstrate possible problems you might encounter pretty well, make sure to use STM though for real life multithreading purposes.

    • @joshuakb2
      @joshuakb2 2 ปีที่แล้ว

      What's wrong with using MVars and Channels in "real life" code?

  • @philipphagenlocher
    @philipphagenlocher  4 ปีที่แล้ว +7

    A few remarks: The examples shown are not the prettiest (no exception handling with threads is never a good idea!) and using MVar and Chan for purposes of synchronization is not good practice! There are other datatypes (QSem, QSemN) for this purpose. MVar and Chan are generally not safe and multithreaded code should use Software Transactional Memory which we will look at in another video. System.IO functions are automatically multiplexed when using lightweight threads (spawned by forkIO) but as we have seen: That does not always work! ;)

    • @Nil44419
      @Nil44419 4 หลายเดือนก่อน +1

      Thanks for the series!

  • @aegistube
    @aegistube 4 ปีที่แล้ว

    Awesome!!! Thank you so much!!!

  • @Silent.
    @Silent. ปีที่แล้ว

    Concurrency with Mvar and channels reminds me of concurrency with C

  • @micknamens8659
    @micknamens8659 2 ปีที่แล้ว

    Another way to use the mutex would be to start with an empty MVar. A thread would try to store its token in it and would have to wait for the MVar to be empty (again). This approach would also allow to store some information about the locking thread in the lock token. Btw. is there a command to "peek" into an MVar, i.e. for reading w/o removing the value from the MVar?

    • @valcron-1000
      @valcron-1000 ปีที่แล้ว

      Take a look at "withMVar"

  • @maxreuv
    @maxreuv 4 ปีที่แล้ว +1

    Very good

  • @lpi3
    @lpi3 3 ปีที่แล้ว +1

    I would use replicateM in place of mapM

  • @shutterrecoil
    @shutterrecoil 2 ปีที่แล้ว

    putStrLn mutex needs a bracket.

  • @kaksisve4012
    @kaksisve4012 3 ปีที่แล้ว +4

    [18:36] I think you can use `replicateM_`.