Technology Corner

Home » C- Language » Process Synchronization (Part 1)

Process Synchronization (Part 1)

Enter your email address to follow this blog and receive notifications of new posts by email.

Join 80 other followers

Twitter updates

Error: Twitter did not respond. Please wait a few minutes and refresh this page.

Archives

RSS InfoQ Feeds

  • How Google Develops New Managers
    Alex Langshur, host of Google Partners Podcasts, has organized the podcast Google HR secrets: identifying & developing great managers, interviewing Sarah Calderon, People Development at Google, on how Google selects, trains, and develops their managers. By Abel Avram
  • Presentation: Cognitive Services, Next Step in Creating Our Robot Overlords
    Harold Pulcher discusses Cognitive Services, how to get started using them, and how to incorporate speech, image, and facial recognition into an application. By Harold Pulcher
  • Presentation: Control Flow Integrity Using Hardware Counters
    Jamie Butler and Cody Pierce discuss a new system for early detection and prevention of unknown exploits. Their system uses Performance Monitoring Unit hardware to enforce coarse-grained Control Flow Integrity (CFI). They intend to prove that their approach is effective and suitable for practical use, while staying resistant to bypass. By Jamie Butler
  • JetBrains Launches GoLand Go IDE
    JetBrains has moved its Go IDE from its early access programme to market. Now branded as GoLand, the IDE extends the IntelliJ platform making its core functionality specific to Go. This follows suit with their other language-specific tools such as PyCharm for Python and RubyMine for Ruby. By Andrew Morgan
  • Panel on the Future of AI
    An SF QCon panel on the future of AI explored some issues facing machine learning today. The areas explored: critical issues facing AI right now, how has technology changed the way people are hired, how non-leading edge companies make the best use of current technologies, what the role of humans in relation to AI is, and exciting new breakthroughs on the imm […]
  • Microsoft Updates Cosmos DB with Cassandra Support and Provides Better Availability Guarantees
    Last month at Microsoft Connect 2017, Azure Cosmos DB received several new updates, including support for using the Cassandra NoSQL database API and increased guarantees for availability. With the Cassandra NoSQL database API, customers can run operations inside Cosmos DB on a data model. The availability guarantee moves from 99.99 percent to 99.999 percent. […]
  • Article: Approximate Computing on WSO2: Explaining Approximation Algorithms in an Applied Setting
    In this article, we describe an example real world application of API monitoring which gets benefit by using approximate stream processing. We developed the application on top of WSO2 Stream Processor as Siddhi extension. Siddhi is the complex event processing library which acts as the event processing engine of WSO2 Stream Processor. By Chamod Samarajeewa
  • Rust in Visual Studio and VS Code
    Daniel Griffen has released a preview version of a Rust language service for Visual Studio. This plugin requires Visual Studio 2017 Preview, an experimental release stream for testing new VS features. By Jonathan Allen
  • Article: Key Takeaway Points and Lessons Learned from QCon San Francisco 2017
    The eleventh annual QCon San Francisco was the biggest yet, bringing together over 1,800 team leads, architects, project managers, and engineering directors. By Abel Avram
  • Article: Q&A With Eberhard Wolff On the Book “A Practical Guide to Continuous Delivery”
    Eberhard Wolff speaks with InfoQ about his work "Continuous Delivery: A Practical Guide", where we detail some of the major concepts behind successful CD adoption and the ripple-effect it can have on developer productivity and quality of service. By Dylan Raithel

We can divide processes in two Categories

1) Co-operative Processes

2) Independent Processes

Co-operative processes are those where the execution of one process affects or affected by other process and if they are not dependent than they are independent processes.

In this tutorial we will study :-

1) problems

2) Conditions to achieve synchronization

3) Solutions to achieve synchronization (which will cover both wrong & right solutions)

Lets Start with Problems which we faced during implementing  Co-operative processes

Producer- Consumer Problem :

The problem describes two processes, the producer and the consumer, who share a common, fixed-size buffer used as a queue. The producer’s job is to generate a piece of data, put it into the buffer and start again. At the same time, the consumer is consuming the data (i.e., removing it from the buffer) one piece at a time. The problem is to make sure that the producer won’t try to add data into the buffer if it’s full and that the consumer won’t try to remove data from an empty buffer.

Consider the Following Program

Producer Code

Int Count =0;

Void producer(void){

int temp;

While(true){

Produe_item(itemp);

while(count==n);

buffer[in]=temp;

in=(in + 1)mod n ;

count=count+1;

}

}

Consumer Code

void consumer(void){

int itemc;

while(true)

{

while(count==0);

itemc=buffer[out];

out=(out+1)mod n;

count=count-1;

process.item(item c);

}

}

can you find any error in the above programs?

when we see these programs individually than these programs works fine but if both of these programs have to work on same data , same resources than they fail to achieve synchronization  which results in inconsistency , loss of data and sometimes can cause DEADLOCK.

Now before continuing to  the next Topic lets know some important terms

Critical Section :-  The portion of program where shared resource or the shared variables is placed

Non Critical Section :- The portion of program which is independent to respective processes

Race Condition :- The condition in which the output of the process depends on execution sequence of statements

Conditions which are important to achieve Synchronization :

1) Mutual Exclusion :- No two processes may be simultaneously present inside the Critical Section at any point of time.

2) Progress :- No process running outside the critical section should block the other interested processes from entring into critical section when critical section is free.

3) Bounded waiting :- No process should have to wait forever to enter into critical section .i.e. their should  be a bound on getting chance to enter into critical section .

(note : – if any solution which is not following bounded waiting than their is a possibility of starvation.)

4) No assumption related to hardware of the process or speed should be taken .

Continued …

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blogs I Follow

%d bloggers like this: