Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi,

I am trying to find an idea for a multi-threaded console application. I am just trying to get better at windows API multi-threading, but i am unsure of an application I should create. Can someone give me and Idea of an application to create?

Thanks,
robNO.
Posted

1 solution

I enjoyed creating multi-threaded console applications. This is also a good way to research some things.

I would suggest you an interesting problem: implementation of Dining philosophers problem, see http://en.wikipedia.org/wiki/Dining_philosophers_problem[^].

You will need to program each philosopher represented by a separate thread; and there can be different way to represent the forks: they can be either threads or some other type of resources. In all cases, they should be resources shared by philosophers. I knew version when different thread synchronization primitives are used, including sockets (originally, sockets was implemented for IPC).

In all cases, you will need to demonstrate getting philosophers in a circular dead lock, when each philosopher gets a left fork and wait perpetually for a right fork. If the problem is solved correctly, getting into the deadlock should be probabilistic. In particular, you're not allowed to alter the algorithm based in a fork or philosopher identity such as individual number (which only should be used for output on your console). No "ifs". I would say, no its no buts. :-)

The problem is pretty easy to implement, yet it gets you into the very depth of multi-threading concepts and problems. I would say, it is a must for every software developers. Unfortunately, from my experience I knew not so many developers well familiar with the problem. I'm not sure, maybe others are not true. :-)

For a bonus, you can design an option where the deadlock is avoided. This is not so interesting as the main problem demonstrating the deadlock, which should be solved first.

Think about software (library) which could detect this kind of deadlocks. Warning: this is a very difficult task.

There was an interesting story about this problem. Recently, some patient asked for help with solving the dining philosophers problem and presented some code. The code was fill of methods working with philosophers and forks, all apparently working without creating a single thread (!). Imagine the level of confusion. As you asked about threading from the very beginning, you won't have this problem. :-) I really appreciate your drive for good self-education.

Good luck,
—SA
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900