#header-inner {background-position: right !important; width: 100% !important;}


Basics of Concurrent Programming.

Concurrent work is multiple works happening at the same time.

Process is a running program.

Thread (lightweigh process, LWP) is object inside heavyweight process that has it's own control & that shares resources with other threads in the same process.

Critical Section.

Critical section is a code section that can be accessed by only one process or thread at the same time.

Critical section has uses for example in banking: we do not want data to be overwritten as it's written by other process, or read during writing.

Example pseudocode:

process P;

  while true do

Source: my partial education (see: [7]), my experience.

Readers & Writers.

In computer science, the readers-writers problem is an example of a common computing problem in concurrency.

Shared resource is abstracted as a Reading Room.

More than one Reader may be in a Reading Room, but if writer is in a Reading Room - no one else can be there.

An example algorithm for handling the readers-writers problem is as follows:

Reader's beginning protocol:
  reader waits (goes asleep), if there's writer in a reading room.

Writer's beginning protocol:
  writer waits (goes asleep), if there's someone in a reading room.

Reader's end protocol:
  if is last exitting person, then awakens & lets writer in - if writer waits.

Writer's end protocol:
  if readers wait, then awakens them all, otherwise, if writer waits, awakens one.

There should be a limit on maximum number of readers let in in a reading room, when writer(s) is/are awaiting.

Source: my partial education (see: [7]), my experience.

See also: Petersen's Algorithm, Classic Concurrency Problems, Petri Nets.

No comments:

Post a Comment