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

  Рет қаралды 9,147

Philipp Hagenlocher

Philipp Hagenlocher

Күн бұрын

Пікірлер: 20
@densidad13
@densidad13 7 ай бұрын
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 2 жыл бұрын
Thanks for sharing all your wisdom!
@Parapascal
@Parapascal 2 жыл бұрын
Thank you very much. Another great explanation
@HyperSimplex
@HyperSimplex 5 ай бұрын
great videos!
@TheWombatGuru
@TheWombatGuru 2 жыл бұрын
Very clear, thank you!
@loucascubeddu
@loucascubeddu Жыл бұрын
So it's an infinite loop to check the end of threads ? I think that Semaphores were better in that case, no?
@0LoneTech
@0LoneTech 3 ай бұрын
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.
@designernasser
@designernasser 4 жыл бұрын
Good stuff. Please fix your mic! I like the content, but the constant mic glitches are annoying.
@philipphagenlocher
@philipphagenlocher 4 жыл бұрын
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
@danconcep
@danconcep 2 жыл бұрын
I do not understand how this is pure. Is result mutable?
@luisenriquemunozmartin6690
@luisenriquemunozmartin6690 2 жыл бұрын
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 2 жыл бұрын
@@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 11 ай бұрын
​ @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 3 ай бұрын
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.
@dforj9212
@dforj9212 3 жыл бұрын
Hey! Very good vids, but as of now it's really hard to follow because of the horrible sound
@canelonism
@canelonism 3 жыл бұрын
ily
Haskell for Imperative Programmers #31 - Weak Head Normal Form
23:13
Philipp Hagenlocher
Рет қаралды 8 М.
Haskell for Imperative Programmers #29 - Semaphores (QSem, QSemN)
16:02
Philipp Hagenlocher
Рет қаралды 6 М.
The evil clown plays a prank on the angel
00:39
超人夫妇
Рет қаралды 48 МЛН
Что-что Мурсдей говорит? 💭 #симбочка #симба #мурсдей
00:19
Мясо вегана? 🧐 @Whatthefshow
01:01
История одного вокалиста
Рет қаралды 7 МЛН
Haskell for Imperative Programmers #28 - Concurrency & Threads
26:12
Philipp Hagenlocher
Рет қаралды 14 М.
Haskell for Imperative Programmers #35 - Semigroup & Monoid
20:42
Philipp Hagenlocher
Рет қаралды 14 М.
Haskell for Imperative Programmers #32 - DeepSeq
22:13
Philipp Hagenlocher
Рет қаралды 4,3 М.
Software Transactional Memory
9:32
Ladders Engineering
Рет қаралды 5 М.
FizzBuzz - You Suck at Coding [0]
12:35
Ben Awad
Рет қаралды 406 М.
Haskell for Imperative Programmers #33 - Parallelism
56:39
Philipp Hagenlocher
Рет қаралды 8 М.
Why Can't We Make Simple Software? - Peter van Hardenberg
41:34
Handmade Cities
Рет қаралды 144 М.
Haskell for Imperative Programmers #37 - Arrows
13:15
Philipp Hagenlocher
Рет қаралды 11 М.
Transactional Memory for Concurrent Programming
16:33
Joshua Ball
Рет қаралды 4,9 М.
The evil clown plays a prank on the angel
00:39
超人夫妇
Рет қаралды 48 МЛН