简体   繁体   English

在活动图中建模线程间通信

[英]Modelling inter thread communication in activity diagram

I am trying to model an application which runs multiple concurrent flows.我正在尝试 model 运行多个并发流的应用程序。 In this situation multiple threads can create events and store them in a buffer which are then collected and displayed by another thread.在这种情况下,多个线程可以创建事件并将它们存储在缓冲区中,然后由另一个线程收集和显示。 The receiving thread is supposed to block and wait for incoming events.接收线程应该阻塞并等待传入的事件。

I have currently modelled it like this:我目前是这样建模的: 在此处输入图像描述 This example uses object flows.此示例使用 object 流。 However I am not sure if this is the correct way to model this type of inter thread communication.但是我不确定这是否是 model 这种类型的线程间通信的正确方法。

The other option I was looking at is using signals but I'm not sure about that either.我正在查看的另一个选项是使用信号,但我也不确定。 Any help would be appreciated.任何帮助,将不胜感激。

Every activity requires all tokens to be offered before it can start.每项活动都需要提供所有代币才能开始。 You will have to use a buffer node as a queue.您将不得不使用缓冲区节点作为队列。

Object flows capture inter thread communication well. Object 流很好地捕获了线程间通信。

You could also use signals, if you want to be more specific and your system uses in fact messages.如果您想要更具体并且您的系统实际上使用消息,您也可以使用信号。

There is one problem in your diagram though: The Display Event action consumes all offered control tokens and one object token on each invocation.但是您的图表中存在一个问题: Display Event操作在每次调用时消耗所有提供的控制令牌和一个 object 令牌。 I can't tell from your diagram, but probably there is only one control token.我无法从您的图表中看出,但可能只有一个控制令牌。 That means, the action will only run once.这意味着,该操作只会运行一次。 The solution is, to delete the control flow.解决办法是,删除控制流。 The action then starts for each incoming object token.然后针对每个传入的 object 令牌开始该操作。

Each output pin acts as a local buffer.每个 output 引脚都充当本地缓冲区。 If tokens are generated faster than the event can be displayed, tokens will potentially pile up in multiple pins.如果令牌的生成速度快于事件的显示速度,则令牌可能会堆积在多个图钉中。 In this case it is undefined which pin will be the source of the next token.在这种情况下,未定义哪个引脚将成为下一个令牌的来源。 This is not necessarily a problem, but if tokens shall be processed in chronological order, you need to use a central buffer.这不一定是个问题,但如果要按时间顺序处理令牌,则需要使用中央缓冲区。 The symbol is a rectangle with the keyword «central buffer»该符号是一个带有关键字 «central buffer» 的矩形

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM