Haskell for Imperative Programmers #30 - Software Transactional Memory (STM)

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

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

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

    I've seen many videos in this series so far and have to congratulate you for the clear explanation style. I've heard about the STM paper before and think I'm now in a position to try to uderstand it. I'll like the refereces to the conceptual sources! Thank you.

  • @luisenriquemunozmartin6690
    @luisenriquemunozmartin6690 ปีที่แล้ว

    Thanks for sharing all your wisdom!

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

    Thank you very much. Another great explanation

  • @HyperSimplex
    @HyperSimplex 3 หลายเดือนก่อน

    great videos!

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

    Very clear, thank you!

  • @designernasser
    @designernasser 4 ปีที่แล้ว +14

    Good stuff. Please fix your mic! I like the content, but the constant mic glitches are annoying.

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

      Totally agree with you. Sadly, I don't have access to my usual setup right now and currently do the series on a 10 year old laptop which seems to cause problems when recording my screen. I'll look into fixing/improving it!

    • @kovacsgyorgy5043
      @kovacsgyorgy5043 3 ปีที่แล้ว

      @@philipphagenlocher Watching the video with 1.25 x or 1.5 x speed makes it slightly easier on the ears :)

    • @tobiasdean7629
      @tobiasdean7629 3 ปีที่แล้ว

      @Everett Santana Flixportal :P

    • @everettsantana6058
      @everettsantana6058 3 ปีที่แล้ว

      @Tobias Dean Thanks, I went there and it seems like a nice service =) Appreciate it!

    • @tobiasdean7629
      @tobiasdean7629 3 ปีที่แล้ว

      @Everett Santana glad I could help :D

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

    Hey! Very good vids, but as of now it's really hard to follow because of the horrible sound

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

    So it's an infinite loop to check the end of threads ?
    I think that Semaphores were better in that case, no?

    • @0LoneTech
      @0LoneTech หลายเดือนก่อน

      They are very similar. With a semaphore, you'd have waitForCounter wait on the semaphore n times, waking up for each addToResult. With STM, each retry knows the STM variables that have been accessed in that transaction were in a state that didn't let the transaction complete, so it can be suspended until they change.
      The semaphore just supports two transactions; increment, and decrement once not zero. This example replaced the latter with read sum once endCtr is n.
      The key advantage is that STM lets us write the logic, rather than worry about lock orders, matched semaphore step sizes, or how many threads are waiting for a broadcast, or whether every place accessing a variable has used the correct lock to do so.

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

    ily

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

    I do not understand how this is pure. Is result mutable?

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

      I'm not a haskell expert (correct me if I'm wrong), but how I understand this, is that instead of mutating the result you're using a new one each time you're writing on it. Similar like IO () Monad generates a new World' from World, here STM Monad generates a new Result' from the previous Result. But I'm sure internally the compiler mutates the same shared memory.

    • @danconcep
      @danconcep ปีที่แล้ว

      @@luisenriquemunozmartin6690 no, this is not a new result. It is using the same result as the input and it is getting a different value. It is not pure.

    • @lukasjerabek2504
      @lukasjerabek2504 9 หลายเดือนก่อน

      ​ @danconcep its not pure, you need sideefects to work with threads. In lesson 27 on Exceptions he suggests to use "Use Maybe and Either because they are purely functional" instead of exceptions he also says: "purely functional code has no idea what exception is" and "There are things that only execeptions can handle - IO, Threads, System, these things cant be solved only with Maybe and Either."

    • @0LoneTech
      @0LoneTech หลายเดือนก่อน

      Result is a TVar, which is conditionally mutable. STM transactions run via atomically can alter it, but only atomically.
      atomically produces an IO action, and only the runtime can actually perform those, and that's where impure effects occur.
      Because STM actions run atomically, they cannot directly observe mutation. If mutation to their observed state occurs, they will retry or fail. The order they run, when started via threads with forkIO, is nondeterministic.
      As far as addToResult or waitForCounter are concerned, TVars are just like the State monad; one input, one output, like a pure function. Retry means some other input state must occur, and automatically builds a precondition to wait for before sum can be returned.