多线程控制台应用程序的想法 [英] Multi-Threaded Console Application Ideas

查看:64
本文介绍了多线程控制台应用程序的想法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在尝试为多线程控制台应用程序找到一个想法.我只是想在Windows API多线程上做得更好,但是我不确定应该创建一个应用程序.有人可以给我和创建应用程序的想法吗?

谢谢,
robNO.

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.

推荐答案

我喜欢创建多线程控制台应用程序.这也是研究某些事物的好方法.

我会建议您一个有趣的问题:餐饮哲学家问题的实现,请参见 http://en.wikipedia.org/wiki/Dining_philosophers_problem [ ^ ].

您将需要编写由单独线程代表的每个哲学家的程序;可以用不同的方式表示派生:它们可以是线程,也可以是其他类型的资源.在任何情况下,它们都应该是哲学家共享的资源.我知道使用不同的线程同步原语(包括套接字)的版本(最初,套接字是为IPC实现的).

在所有情况下,您都需要证明让哲学家陷入圆形的死锁,当每个哲学家得到左叉并永久等待右叉时.如果问题得到正确解决,则陷入僵局应该是概率性的.特别是,不允许您基于分叉或哲学家身份(例如个人号码)更改算法(仅应将其用于控制​​台上的输出).没有如果".我会说,不,不,而是. :-)

这个问题很容易实现,但是它使您深入了解多线程概念和问题.我会说,这对于每个软件开发人员都是必须的.不幸的是,根据我的经验,我知道没有多少开发人员对这个问题很熟悉.我不确定,也许其他人不是真的. :-)

作为奖励,您可以设计一个避免死锁的选项.这没有显示死锁的主要问题那么有趣,应首先解决.

考虑可以检测到这种死锁的软件(库).警告:这是一项非常艰巨的任务.

关于这个问题有一个有趣的故事.最近,一些患者寻求解决用餐哲学家问题的帮助,并提出了一些代码.代码中包含了与哲学家和fork一起使用的方法,显然所有这些方法都无需创建单个线程(!).想象一下混乱的程度.当您从一开始就询问线程时,就不会遇到这个问题. :-)非常感谢您为良好的自我教育所做的努力.

祝你好运,
—SA
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


这篇关于多线程控制台应用程序的想法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆