Threads and concurrency - summary points from presentation: Difference between revisions

From Planimate Knowledge Base
Jump to navigation Jump to search
m (1 revision(s))
mNo edit summary
Line 1: Line 1:
'''''<font face="Optima"><font size="3">Introduction<br /> </font></font>'''''<font face="Symbol">• <font size="4">Concurrency: More than one activity at the same time<br /><font face="Symbol">• Models usually contain concurrent activity<br /><font face="Symbol">• Models are inherently parallel programs<br /><font face="Symbol">• The (runtime) engine itself only processes one activity at a time (even on dual CPUs). <br /><br />'''''<font size="3">Events And Their Ordering<br /> </font>'''''<font face="Symbol">• <font size="4">Events generate activity in a model<br /><font face="Symbol">• Activity generates further events<br /><font face="Symbol">• Events are sorted by time in the FEC<br /><font face="Symbol">• Its not safe to rely on the order that events in the FEC at the same time will be processed<br /><font face="Symbol">• Past models forced order using delays<br /><font face="Symbol">• Order can be assured by understanding threads<br />'''''<font size="3"><br /> Threads<br /> </font>'''''<font face="Symbol">• Items flow between points of capacity. A moving item (flowing) is a thread<br /><font face="Symbol">• Events trigger item movement hence events trigger threads<br /><font face="Symbol">• A thread generally cannot be interrupted<br /><font face="Symbol">• All activities within one thread will occur together and in their flow sequence<br /><font face="Symbol">• A thread ends when an item reaches a point of capacity<br /><font face="Symbol">• Threads can post “side effect” events<br /><font face="Symbol">• The next thread to execute is well defined for some specific cases<br />'''''<br /> Co-ordinating Threads<br /> '''''<font face="Symbol">• <font size="4">One to One vs. One to Many<br /><font face="Symbol">• Attribute Gate (One to One)<br /><font face="Symbol">• Messages (One to One)<br /><font face="Symbol">• Normal, Directed, Immediate<br /><font face="Symbol">• Broadcasts (One to Many)<br /><font face="Symbol">• Global, Scoped, Directed<br /><font face="Symbol">• Splitters (One to Many)<br /><font face="Symbol">• Immediate Messages<br />'''''<font size="3"><br /> Messaging from a dispatcher<br /> </font>'''''<font face="Symbol">• <font size="4">Gives a One to One co-ordination of threads<br /><font face="Symbol">• Original item waits until message item completes and “returns”<br /><font face="Symbol">• Thread order is maintained if the message item leaves in its original thread<br /><font face="Symbol">• Can dynamically direct message to a location determined at runtime<br /><br />'''''<font size="3">Broadcasting from a dispatcher<br /> </font>'''''<font face="Symbol">• <font size="4">Combines One To Many and Wait Until<br /><font face="Symbol">• Broadcasts all sent before item leaves<br /><font face="Symbol">• Only guarantees execution of the initial thread after each broadcast entry<br /><font face="Symbol">• Sending the broadcast to all entries takes higher priority than processing other events at the same time<br /><font face="Symbol">• Unsafe to rely on the order that the entries will receive the broadcast<br /><br />'''''<font size="3">Avoiding Concurrency Problems<br /> </font>'''''<font face="Symbol">• <font size="4">Minimise creating simultaneous item threads when possible<br /><font face="Symbol">• Use a single item to process events in a system to avoid concurrency issues and conflicts which are more likely with multiple items<br /><font face="Symbol">• Call common code using messages<br /><font face="Symbol">• Minimise capacity objects in threads to avoid creating extra events<br /><br />'''''<font size="3">Avoiding Concurrency Problems (2)<br /> </font>'''''<font face="Symbol">• <font size="4">Try perform any Graphical iteration without capacity objects in the loop<br /><font face="Symbol">• Do not rely on the order that broadcasts get sent, items leave servers etc. Splitters are OK<br /><font face="Symbol">• Use Immediate Messages to call a thread from within a routine (within a thread)<br />'''''<font size="3"><br /> Cases where thread order is defined<br /> </font>'''''<font face="Symbol">• <font size="4">Empty Queue / normal Dispatcher which is not blocked moves item out in next thread<br /><font face="Symbol">• Message/Broadcast Dispatcher - same<br /><font face="Symbol">• Splitter which is not blocked<br /><font face="Symbol">• Zero delay multiserver ONLY if thread is initiated by an FEC event - not a broadcast or splitter<br />'''''<font size="3"><br /> Pausing Issues<br /> </font>'''''<font face="Symbol">• <font size="4">A model can only be paused between events, never within a thread, broadcast send etc.<br /><font face="Symbol">• Earlier versions of Planimate could be paused between any pair of events<br /><font face="Symbol">• This meant that a model could be paused before all events at the current time were processed, leading to incomplete updates.<br /><font face="Symbol">• Engine now “pauses” only after all events at the current time have been processed<br /><br />'''''<font size="3">Future Directions<br /> </font>'''''<font face="Symbol">• <font size="4">User Thread - Persistent Items<br /><font face="Symbol">• Handling graphical looping better<br /><font face="Symbol">• Flexible class changes within a thread<br /><font face="Symbol">• Threads spanning multiple instances/machines<br /><font face="Arial"><br /> </font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font>
== Threads and concurrency - summary points from presentation 2001 ==
----
 
[[Category:Blocking]]
=== Introduction ===
* Concurrency: More than one activity at the same time
* Models usually contain concurrent activity
*• Models are inherently parallel programs
*• The (runtime) engine itself only processes one activity at a time (even on dual CPUs).
 
=== Events And Their Ordering ===
* Events generate activity in a model
* Activity generates further events
* Events are sorted by time in the FEC   (Its not safe to rely on the order that events in the FEC at the same time will be processed)
* Past models forced order using delays
* Order can be assured by understanding threads
 
=== Threads ===
* Items flow between points of capacity. A moving item (flowing) is a thread
* Events trigger item movement hence events trigger threads
* A thread generally cannot be interrupted
* All activities within one thread will occur together and in their flow sequence
* A thread ends when an item reaches a point of capacity
* Threads can post “side effect” events
* The next thread to execute is well defined for some specific cases
 
=== Co-ordinating Threads One to One vs. One to Many ===
* Attribute Gate (One to One)
* Messages (One to One)
* Normal, Directed, Immediate
* Broadcasts (One to Many)
* Global, Scoped, Directed
* Splitters (One to Many)
* Immediate Messages
 
=== Messaging from a dispatcher ===
* Gives a One to One co-ordination of threads
* Original item waits until message item completes and “returns”
* Thread order is maintained if the message item leaves in its original thread
* Can dynamically direct message to a location determined at runtime
 
=== Broadcasting from a dispatcher ===
* Combines One To Many and Wait Until
* Broadcasts all sent before item leaves
* Only guarantees execution of the initial thread after each broadcast entry
* Sending the broadcast to all entries takes higher priority than processing other events at the same time
* Unsafe to rely on the order that the entries will receive the broadcast
 
=== Avoiding Concurrency Problems ===
* Minimise creating simultaneous item threads when possible
* Use a single item to process events in a system to avoid concurrency issues and conflicts which are more likely with multiple items
* Call common code using messages
* Minimise capacity objects in threads to avoid creating extra events
* Try perform any Graphical iteration without capacity objects in the loop
* Do not rely on the order that broadcasts get sent, items leave servers etc. Splitters are OK
* Use Immediate Messages to call a thread from within a routine (within a thread)
 
=== Cases where thread order is defined ===
* Empty Queue / normal Dispatcher which is not blocked moves item out in next thread
* Message/Broadcast Dispatcher - same
* Splitter which is not blocked
* Zero delay multiserver ONLY if thread is initiated by an FEC event - not a broadcast or splitter
 
=== Pausing Issues ===
* A model can only be paused between events, never within a thread, broadcast send etc.
* Earlier versions of Planimate could be paused between any pair of events This meant that a model could be paused before all events at the current time were processed, leading to incomplete updates.
* Engine now “pauses” only after all events at the current time have been processed
* This can be overridden using the Pauseable Zero Delay multiserver option
 
=== Future Directions ===
* User Thread - Persistent Items (now present as a Restart Dispatcher mode)
* Handling graphical looping better (has been improved to support more complex loops)
* Flexible class changes within a thread (implemented for modules)
* Threads spanning multiple instances/machines (network broadcasts)
 
<font size="2">idkbase note 206</font>
 
[[Category:Runtime Engine]]
[[Category:Runtime Engine]]
[[Category:Thread]]
[[Category:Thread]]
[[Category:Zero Time]]
[[Category:Zero Time]]
[[Category:concurrency]]
[[Category:Discussion]]
<font size="2">idkbase note 206</font>

Revision as of 14:25, 12 January 2008

Threads and concurrency - summary points from presentation 2001

Introduction

  • Concurrency: More than one activity at the same time
  • Models usually contain concurrent activity
  • • Models are inherently parallel programs
  • • The (runtime) engine itself only processes one activity at a time (even on dual CPUs).

Events And Their Ordering

  • Events generate activity in a model
  • Activity generates further events
  • Events are sorted by time in the FEC (Its not safe to rely on the order that events in the FEC at the same time will be processed)
  • Past models forced order using delays
  • Order can be assured by understanding threads

Threads

  • Items flow between points of capacity. A moving item (flowing) is a thread
  • Events trigger item movement hence events trigger threads
  • A thread generally cannot be interrupted
  • All activities within one thread will occur together and in their flow sequence
  • A thread ends when an item reaches a point of capacity
  • Threads can post “side effect” events
  • The next thread to execute is well defined for some specific cases

Co-ordinating Threads - One to One vs. One to Many

  • Attribute Gate (One to One)
  • Messages (One to One)
  • Normal, Directed, Immediate
  • Broadcasts (One to Many)
  • Global, Scoped, Directed
  • Splitters (One to Many)
  • Immediate Messages

Messaging from a dispatcher

  • Gives a One to One co-ordination of threads
  • Original item waits until message item completes and “returns”
  • Thread order is maintained if the message item leaves in its original thread
  • Can dynamically direct message to a location determined at runtime

Broadcasting from a dispatcher

  • Combines One To Many and Wait Until
  • Broadcasts all sent before item leaves
  • Only guarantees execution of the initial thread after each broadcast entry
  • Sending the broadcast to all entries takes higher priority than processing other events at the same time
  • Unsafe to rely on the order that the entries will receive the broadcast

Avoiding Concurrency Problems

  • Minimise creating simultaneous item threads when possible
  • Use a single item to process events in a system to avoid concurrency issues and conflicts which are more likely with multiple items
  • Call common code using messages
  • Minimise capacity objects in threads to avoid creating extra events
  • Try perform any Graphical iteration without capacity objects in the loop
  • Do not rely on the order that broadcasts get sent, items leave servers etc. Splitters are OK
  • Use Immediate Messages to call a thread from within a routine (within a thread)

Cases where thread order is defined

  • Empty Queue / normal Dispatcher which is not blocked moves item out in next thread
  • Message/Broadcast Dispatcher - same
  • Splitter which is not blocked
  • Zero delay multiserver ONLY if thread is initiated by an FEC event - not a broadcast or splitter

Pausing Issues

  • A model can only be paused between events, never within a thread, broadcast send etc.
  • Earlier versions of Planimate could be paused between any pair of events This meant that a model could be paused before all events at the current time were processed, leading to incomplete updates.
  • Engine now “pauses” only after all events at the current time have been processed
  • This can be overridden using the Pauseable Zero Delay multiserver option

Future Directions

  • User Thread - Persistent Items (now present as a Restart Dispatcher mode)
  • Handling graphical looping better (has been improved to support more complex loops)
  • Flexible class changes within a thread (implemented for modules)
  • Threads spanning multiple instances/machines (network broadcasts)

idkbase note 206