How to use threads in C++11 (multitasking, mutual exclusion, etc.)

preview_player
Показать описание
In this tool-assisted education video I explain the tools that C++11 introduced for creating multi-threaded programs. We will study each concept individually from #threads to condition variables and from futures to promises.

ENGLISH-LANGUAGE CLOSED CAPTIONS ARE AVAILABLE.

Music used in the video, in order of appearance:
– Wizardry V :: Artifacts (Kentarou Haneda)
– Star Ocean :: Calm Time (Motoi Sakuraba)
– Wonder Project J :: House (Akihito Mori)

Footage music (also played through homebrew software):
– Cave Story :: Geothermal

Cameras used: Canon EOS 1200D, Canon PowerShot SX110IS
Lens: Tokina AT-X PRO 11-16mm F2.8 DX
Programming footage in: DOSBox
Resampling with: ffmpeg
Video editing in: kdenlive
Audio editing in: audacity & kdenlive
Muxing in: mkvmerge

Production dates: 2015-12-03 through 2016-01-22
Desktop computer is: Raspberry Pi
Secret code: OwjQkUo9Bgk
Compilers used: GCC 5.3.1
Robot is: Nao V4

If anything in the video requires clarification, please write a comment. I try to reply to every unique comment that contains a question addressed to me. Please make sure your privacy settings (possibly found as far as in Google+) will not prevent me from actually replying.

The editor used in the video, with Mario and all, is a 16-bit homebrew editor that only runs in 16-bit DOS. You can download it at the download page, but note that it is only designed for video making. It’s not meant for actual use, but it does work and is largely modelled after Joe.

Linux is used under DOSBox (for purpose of video production only) by using a modified version of DOSBox that provides forkpty() functions as DOS interrupts, and a homebrew terminal program running in DOS, that supports xterm-256color escapes. The terminal program is useless without the patched version of DOSBox (and furthermore this patch will only work in Linux). Nonetheless you can find both on the download page, linked above.

Reference material used and highly recommended:

Note to self: Possible topics for a hypothetical second episode:
– Thread-local variables
– Memory order declarations
– What the standard says about memory interactions between threads
– What the standard guarantees about when variable changes are committed into RAM
– Clustering
– CPU affinity

#Bisqwit #ThreadProgramming #Tutorial #Parallelism #Programming
Рекомендации по теме
Комментарии
Автор

Information evacuated from annotations that YouTube dropped support for in 2019-01-15:
12:35 “std::async is more convenient to use than std::thread, but std::thread has lower overhead. Use std::async when you are running something "asynchronously" on the background and you need the results only later at some particular point in the program. Use std::thread when you are doing threads in bulk for parallel processing.”
13:13 “You would use std::promise when you want to send a value into std::future, while still continuing to execute the thread/asynchronous function.”
13.39 “Clarification: The std::promise is not the only way to pass exceptions. E.g. if the function, that is called with std::async, throws an exception and it is not caught, it will be transmitted through the std::future associated with the std::async call. The same goes with std::packaged_task.”
14:00 “In my opinion, the reason why you would use std::future at all, is that it is more convenient than some alternatives composed from lower-level constructs.”
21:33 “Note: Using sched_yield() or std::this_thread::yield() would be a mistake. It is ineffective solution.”

Bisqwit
Автор

it's not like i understand what he's doing, i subscribed cause i wish i could do this. fascinating

yayafitini
Автор

Bisqwit, the world needs more people like you!

CPS
Автор

(Thank you for putting subtitles in all your videos!)

NonTwinBrothers
Автор

You talk very clearly, going straight to the point and not waisting time. I like your tutorial. Thank you!

lfa
Автор

your voice is so soothing i love it, i just listen to your voice while i'm at work

rebecca
Автор

the only problem I have when watching your videos is the amont of informations there is
it's really great and well done. no side talks no long and boring explantions only pure code juice. thanks

whynot-vqly
Автор

Forget threads. `std::cout << "\r"` and `for(const auto& p: {"some", "static" "initialiser", "list", "of", "stuff"})` are both moments where I swore in amazement.

RoamingAdhocrat
Автор

+Mikko Finell It's a matter of whether you prefer thinking much to type little, or thinking little to type lots, to achieve the same outcome. As the saying goes: work smarter, not harder.
(Also, I can't reply to your comment directly. Please check your Google+ privacy settings.)

Bisqwit
Автор

Only 5 minutes mark, it already packed several of new knowledge for me. Thanks!

haxpor
Автор

You Sir are a true gentleman and a pleasure to listen too and learn from ... thanks for sharing your knowledge

CalBart
Автор

His voice and the music is so calm and I could just watch it because it's soo soothing :)

graphoverflow
Автор

You've become one of my favorite broadcasters on YouTube! Your videos are a lot of fun to watch.

whatamievendoing
Автор

Oh, and I was just trying to be educated about this topic a few days ago, how nice of you to share a video about it.
Excellent editing as usual. :)

MarkInD
Автор

Liked the video because of the video's description

luisponce
Автор

Clear, concise and very good explanation 🙏🏻!

Humble_Electronic_Musician
Автор

I love your manner of explanation. Perfect work.

SuperNolane
Автор

You are an example for me, totaly awesome!

josemaria
Автор

Nice to see a new video! Although I don't understand much of it, I kind of get the idea of it. The elgegancy of high level programming always fascinates me :)

mikaelmoizt
Автор

Thanks for the video! I always enjoy hearing about what you have been working on.

jacobsullivan
welcome to shbcf.ru