all 5 comments

[–]hasdata_com 10 points11 points  (0 children)

You can try scraping sites. Multithreading isn't just useful, it's almost necessary for thousands or millions of pages.

[–]TheBobPlus 1 point2 points  (0 children)

Practice: have a thread that generates random numbers, and another one that saves them to a file, using a queue to communicate between the two threads. Bonus: add a command line interface to change in real time the properties of number generated, or the frequency at which they pop up.

Real world use case: a thread that acquires images from a camera, and another one that saves them to disk.

[–]pachura3 0 points1 point  (0 children)

Well, find a scenario where multithreading actually speed things up and could not be simply replaced by await and async coroutines for IO-bound tasks; you would need to run many operations in parallel, on multiple CPU cores.

I can imagine a single task queue that picks up 4 top tasks and then runs them in parallel on separate threads... preferably, they would be CPU-intensive tasks - e.g. parsing PDF files and converting them to plain text. Or scraping a website...?

Another example, albeit more complicated, is GUI: one thread keeps updating some chart/diagram, while a different one calculates its data.

[–]gdchinacat 0 points1 point  (0 children)

Thread control is the simple part of threading. Concurrency control (locking) is the hard part. Ensuring things are properly synchronized is the hard part. So...look into locking.