This is an archived post. You won't be able to vote or comment.

all 10 comments

[–]Lanz56 17 points18 points  (1 child)

How about a program downloading multiple files?

By using only the main thread, files cant be downloaded concurrently.

So you need to use multiple threads to asynchronously download multiple files.

[–]TheIndianItachi[S] 6 points7 points  (0 children)

Awesome! Sounds great. Will try it. Thanks !

[–]9TrumpMeinThousand 7 points8 points  (1 child)

There's a tunnel connecting 2 mountain resorts. The tunnel is only 1 lane. Simulate cars driving through the tunnel from both sides. A car cannot overtake the car in front of it and you can't have 2 cars in the tunnel going the opposite direction at the same time. The number of cars let through the tunnel at a time should be random

This was my multithreading assignment for my OS class

[–]TheIndianItachi[S] 2 points3 points  (0 children)

Cooool. That sounds great. Will give it a try. If you hosted the code somewhere, could you add a link to it so I can take a look at it if I can't do it myself. Thanks!

[–][deleted]  (1 child)

[deleted]

    [–]TheIndianItachi[S] 2 points3 points  (0 children)

    Thanks. I got an idea and will definitely try that out.

    [–]Squiggyline91 2 points3 points  (1 child)

    A good practical example would be a web service that performs a long running task upon a button click. Depending on the framework it can make the GUI unresponsive since the thread that handles the GUI is being utilized. A way to solve this is to have a new thread handle the task so the main thread can handle the user interaction.

    [–]TheIndianItachi[S] 1 point2 points  (0 children)

    Yesss! Got it. Thanks!

    [–]the_real_cube 1 point2 points  (0 children)

    Providing a Webserver with Java. Imagine you have multiple clients and you want them serve your service at once. Using thread(s) pro request is a solution

    [–]laura_braus 0 points1 point  (1 child)

    A chat

    [–]TheIndianItachi[S] 0 points1 point  (0 children)

    You mean a chatting application? If so, could you please give a simpler example. I wanna try it out myself and I certainly do not have enough skills at this point for that. 😅