本文介绍了C#中的并发编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在我的应用程序中实现以下内容?
我们有一个房间,并提供3种类型.首先是将食物送入房间.第二个电流从第一个馈入.第三人从第一流吃饱了.他们可以互相控制.
它必须是并发的.
他们必须在彼此不知情的情况下使用相同的算法!
他们的生活与另一个人息息相关.

How can I implement the following in my application?
We have a room and is available in 3 types. First there is the food that is fed into the room. The second current is fed from the first. The third eat from frist current fed. They can control each other.
It needs to be concurrent.
They must use the same algorithm without the knowledge of each other!
they life relate to another!

推荐答案

    Action      Room A            Room B         Room C
                 full              current=5a     ---
     C increases current
                 full              current=?      ???

and so on


In each tick:
    > Iterate each element in the simulation:
        * The element calculates it's pending new value based on its inputs
          (which are probably derived from the current states of other 
          elements in the simulation.
        * The element caches this value (keeps it private).
    > Iterate each element, again:
        * The element sets its publicised value to be the value it cached
          in the earlier iteration



在您的示例中,房间是模拟中的元素.房间(据我所知,从您的描述中可以看出)发布了其中包含的食物"数量.他们还知道一个或多个其他房间(输入).

请注意,如果一个房间从另一个房间进餐,则食物的收益(在一个房间里)和损失(在另一个房间里)是要在两个房间中缓存的计算值中考虑的值;直到所有元素的第二次迭代,NO元素都不会更新其当前状态.

玩得开心.编写模拟系统通常是非常有益的.



In your example, a room is an element in the simulation. Rooms (as far as I can tell from your description) publish how much ''food'' they contain. They also are aware of one or more other rooms (inputs).

Note that if one room eats from another the gain (in one room) and loss (in the other) of food are values to be accounted for in the calculated value that is cached in the two rooms; until the second iteration across all elements NO element updates its current state.

Have fun. Writing simulation systems is often very rewarding.


这篇关于C#中的并发编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-21 02:17