Search code examples
multithreadingprocesspthreadsdefinition

Really what is event in Threads?


Thread is formally a sequence of events. Some of the events mentioned below

  • Assign to a shared variable
  • Assign to a local variable
  • Invoke method
  • Return from method

So here, It means instruction execution and events are the same or not.

I need to know the difference between the event and instruction execution if they are different?

Can anyone explain what is called an event?

Threads and these events can be seen as state diagrams where threads (programming counter, local variables) are states and events are transitions. Whenever an event happens thread state may change.

Thanks in advance


Solution

  • Internal event is an instruction execution. External event is a mean of communication between threads. They are implemented by special kinds of instructions, which can safely be executed on parallel threads (CAS, compare-and-set, compare-and-swap). The ulimate goal of external event is to pass signal from one thread to another. Usually it is done using a buffer, that is, one thread puts signal in a buffer, and another thread extracts that signal, waithing if no signals are ready.