Haskell for Imperative Programmers #28 - Concurrency & Threads

  Рет қаралды 14,238

Philipp Hagenlocher

Philipp Hagenlocher

Күн бұрын

In this video we explore threads and communication with the datatypes MVar and Chan.
Code: gist.github.com/phagenlocher/...
Documentation:
hackage.haskell.org/package/ba...
hackage.haskell.org/package/ba...
hackage.haskell.org/package/ba...
downloads.haskell.org/~ghc/la...
Further reading:
wiki.haskell.org/Concurrency
en.wikipedia.org/wiki/Concurr...
www.microsoft.com/en-us/resea...
wiki.haskell.org/Parallelism_...
Info on mutexes / locks:
bit.ly/2WaggCM
en.wikipedia.org/wiki/Mutual_...
Timestamps:
00:00 - Basics
03:35 - MVar Datatype
08:21 - Chan Datatype
10:30 - Basic Example and Compilation
15:42 - Chan Example
22:17 - MVar Example
Support me on Ko-fi:
ko-fi.com/phagenlocher

Пікірлер: 21
@adamtafesse8971
@adamtafesse8971 4 жыл бұрын
I am only half way through but I just wanted to say video is a great resource! Clear and concise!
@thomasanderson9351
@thomasanderson9351 4 жыл бұрын
Loving this series!
@nadaxiong
@nadaxiong 4 жыл бұрын
Very clear explanations! Love it!
@LeoOno
@LeoOno 4 жыл бұрын
Thanks for these series, they are helping me a lot :) !
@moisesbr
@moisesbr 2 жыл бұрын
Wow, excellent lesson. Most concurrency gotchas in less than half an hour!
@aegistube
@aegistube 3 жыл бұрын
Awesome!!! Thank you so much!!!
@rifaldhiaw
@rifaldhiaw 4 жыл бұрын
Yeeaa... Finally more expert content. Thank you and please keep it up
@slaser79
@slaser79 4 жыл бұрын
0
@rodrigo_botti
@rodrigo_botti 3 жыл бұрын
Awesome video! I'd like to add something: using finally to release the lock on the mutex. -- takeMVar mutex finally (putStrLn greeting) (putMVar mutex ()) --
@yoshieatspizzad913
@yoshieatspizzad913 2 жыл бұрын
for some reason i find the "show tid" at 11:00 incredibly funny
@MasthaX
@MasthaX 3 жыл бұрын
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?
@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 10 ай бұрын
Take a look at "withMVar"
@Silent.
@Silent. Жыл бұрын
Concurrency with Mvar and channels reminds me of concurrency with C
@maxreuv
@maxreuv 4 жыл бұрын
Very good
@philipphagenlocher
@philipphagenlocher 4 жыл бұрын
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 2 ай бұрын
Thanks for the series!
@lpi3
@lpi3 3 жыл бұрын
I would use replicateM in place of mapM
@shutterrecoil
@shutterrecoil 2 жыл бұрын
putStrLn mutex needs a bracket.
@kaksisve4012
@kaksisve4012 3 жыл бұрын
[18:36] I think you can use `replicateM_`.
Haskell for Imperative Programmers #29 - Semaphores (QSem, QSemN)
16:02
Philipp Hagenlocher
Рет қаралды 6 М.
Haskell for Imperative Programmers #30 - Software Transactional Memory (STM)
24:15
Я обещал подарить ему самокат!
01:00
Vlad Samokatchik
Рет қаралды 3,9 МЛН
УГАДАЙ ГДЕ ПРАВИЛЬНЫЙ ЦВЕТ?😱
00:14
МЯТНАЯ ФАНТА
Рет қаралды 4,2 МЛН
How Many Balloons Does It Take To Fly?
00:18
MrBeast
Рет қаралды 187 МЛН
Haskell for Imperative Programmers #31 - Weak Head Normal Form
23:13
Philipp Hagenlocher
Рет қаралды 8 М.
Interview with an Emacs Enthusiast in 2023 [Colorized]
8:50
Programmers are also human
Рет қаралды 1,1 МЛН
What is a Monad? - Computerphile
21:50
Computerphile
Рет қаралды 597 М.
Haskell for Imperative Programmers #35 - Semigroup & Monoid
20:42
Philipp Hagenlocher
Рет қаралды 13 М.
But how do GPUs actually work?
8:48
Graphicode
Рет қаралды 2,6 М.
CHATGPT DOESN'T REASON! (Top scientist bombshell)
1:42:28
Machine Learning Street Talk
Рет қаралды 3,2 М.
Creator of git, Linus Torvalds Presents the Fundamentals of git
1:10:15
Developers Alliance
Рет қаралды 50 М.
Guest lecture: Concurrency in Haskell
1:31:58
Realfag UiB
Рет қаралды 2,1 М.
Лазер против камеры смартфона
1:01
Newtonlabs
Рет қаралды 717 М.
iPhone 16 с инновационным аккумулятором
0:45
ÉЖИ АКСЁНОВ
Рет қаралды 9 МЛН
Это Xiaomi Su7 Max 🤯 #xiaomi #su7max
1:01
Tynalieff Shorts
Рет қаралды 2 МЛН
Копия iPhone с WildBerries
1:00
Wylsacom
Рет қаралды 7 МЛН
S24 Ultra and IPhone 14 Pro Max telephoto shooting comparison #shorts
0:15
Photographer Army
Рет қаралды 10 МЛН