Implementing Reader-Writer problem.

Implementing Reader-Writer problem.

Program to implement Reader-writer problem using mutex/ semaphore.

Download : Source Code
Description: According to this problem, multiple processes read the database at the same time, but if one process is updating (writing) the database, no other processes may have access to the database, not even readers.
Code :
#include<stdio.h>
#include<sys/types.h>
#include<stdlib.h>
#include<pthread.h>
#include<semaphore.h>
#define N 5
int b;
int readcount;
sem_t mutex,wrt;
void* w()
{
int i=1;
for(i=0;i<N;i++)
{
sem_wait(&wrt);             //wait
b=i;
i++;
//Writing is performed
printf(“\nW :written =%d”,b);
sem_post(&wrt);             //signal
printf(“\nW going to sleep..”);
sleep(2);
}
printf(“Writer is living”);
}
void * r(void * a)
{
int *rr =(int *) a ;
int i;
for(i=0;i<N;i++)
{
sem_wait(&mutex);
readcount++;
if(readcount==1)
sem_wait(&wrt);
sem_post(&mutex);
//Readind is performed
printf(“\nR :read=%d Reader no.=%d “,b,*rr);
printf(“\nReader%d:going to sleep…”,*rr);
sleep(2);
sem_wait(&mutex);
readcount–;
if(readcount==0)             //to check last reader
sem_post(&wrt);
sem_post(&mutex);
}
printf(“Reader no.=%d living”,*rr);
}

void main()
{
pthread_t w1,w2,r1,r2;
int rr1=1,rr2=2;
b=0;
readcount=0;
printf(“\n value of shared variable is %d”,b);
sem_init(&(wrt),0,1);
sem_init(&(mutex),0,1);
//Creating Threads
pthread_create(&w1,NULL,w,NULL);
pthread_create(&r1,NULL,r,(void * )&rr1);
pthread_create(&r2,NULL,r,(void * )&rr2);
pthread_join(w1,NULL);
pthread_join(r1,NULL);
pthread_join(r2,NULL);
}

Implementing Dining Philosopher problem

Implementing Dining Philosopher problem

Explaination- click

C program for the implementation of Dining Philosopher problem :


/***********************************************************
***********************************************************/
 
#include<stdio.h>
#include<semaphore.h>
#include<pthread.h>
  
#define N 5
#define THINKING 0
#define HUNGRY 1
#define EATING 2
#define LEFT (ph_num+4)%N
#define RIGHT (ph_num+1)%N
  
sem_t mutex;
sem_t S[N];
  
void * philospher(void *num);
void take_fork(int);
void put_fork(int);
void test(int);
  
int state[N];
int phil_num[N]={0,1,2,3,4};
  
int main()
{
    int i;
    pthread_t thread_id[N];
    sem_init(&mutex,0,1);
    for(i=0;i<N;i++)
        sem_init(&S[i],0,0);
    for(i=0;i<N;i++)
    {
        pthread_create(&thread_id[i],NULL,philospher,&phil_num[i]);
        printf("Philosopher %d is thinking\n",i+1);
    }
    for(i=0;i<N;i++)
        pthread_join(thread_id[i],NULL);
}
  
void *philospher(void *num)
{
    while(1)
    {
        int *i = num;
        sleep(1);
        take_fork(*i);
        sleep(0);
        put_fork(*i);
    }
}
  
void take_fork(int ph_num)
{
    sem_wait(&mutex);
    state[ph_num] = HUNGRY;
    printf("Philosopher %d is Hungry\n",ph_num+1);
    test(ph_num);
    sem_post(&mutex);
    sem_wait(&S[ph_num]);
    sleep(1);
}
  
void test(int ph_num)
{
    if (state[ph_num] == HUNGRY && state[LEFT] != EATING && state[RIGHT] != EATING)
    {
        state[ph_num] = EATING;
        sleep(2);
        printf("Philosopher %d takes fork %d and %d\n",ph_num+1,LEFT+1,ph_num+1);
        printf("Philosopher %d is Eating\n",ph_num+1);
        sem_post(&S[ph_num]);
    }
}
  
void put_fork(int ph_num)
{
    sem_wait(&mutex);
    state[ph_num] = THINKING;
    printf("Philosopher %d putting fork %d and %d down\n",ph_num+1,LEFT+1,ph_num+1);
    printf("Philosopher %d is thinking\n",ph_num+1);
    test(LEFT);
    test(RIGHT);
    sem_post(&mutex);
}

William Stallings - OPERATING SYSTEMS (PPT)

PowerPoint Slides by William Stallings

          Part 1: Background

Part 2: Processes
Part 3: Memory
Part 4: Scheduling
Part 5: Input/Output and Files
Part 6: Embedded Systems
Part 7: Security
Part 8: Distributed Systems



Computer networks- Transmission modes

Data Transmission modes  

A given transmission on a communications channel between two machines can occur in several different ways. The transmission is characterised by:

  • The direction of the exchanges
  • The transmission mode: the number of bits sent simultaneously
  • Synchronization between the transmitter and receiver

  • Simplex, half-duplex and full-duplex connections

    There are 3 different transmission modes characterised according to the direction of the exchanges:
    • A simplex connection is a connection in which the data flows in only one direction, from the transmitter to the receiver. This type of connection is useful if the data do not need to flow in both directions (for example, from your computer to the printer or from the mouse to your computer...).
                                           Simplex connection
    • A half-duplex connection (sometimes called an alternating connection orsemi-duplex) is a connection in which the data flows in one direction or the other, but not both at the same time. With this type of connection, each end of the connection transmits in turn. This type of connection makes it possible to have bidirectional communications using the full capacity of the line.
                                               Half-duplex connection
    • A full-duplex connection is a connection in which the data flow in both directions simultaneously. Each end of the line can thus transmit and receive at the same time, which means that the bandwidth is divided in two for each direction of data transmission if the same transmission medium is used for both directions of transmission.
                                                  Full-duplex connection

    Serial and parallel transmission

    The transmission mode refers to the number of elementary units of information (bits) that can be simultaneously translated by the communications channel. In fact, processors (and therefore computers in general) never process (in the case of recent processors) a single bit at a time; generally they are able to process several (most of the time it is 8: one byte), and for this reason the basic connections on a computer are parallel connections. 

    Parallel connection

    Parallel connection means simultaneous transmission of N bits. These bits are sent simultaneously over N different channels (a channel being, for example, awire, a cable or any other physical medium). The parallel connection on PC-type computers generally requires 10 wires. 
    Parallel connection

    These channels may be:
    • N physical lines: in which case each bit is sent on a physical line (which is why parallel cables are made up of several wires in a ribbon cable)
    • one physical line divided into several sub-channels by dividing up the bandwidth. In this case, each bit is sent at a different frequency...



    Since the conductive wires are close to each other in the ribbon cable, interference can occur (particularly at high speeds) and degrade the signal quality... 

    Serial connection

    In a serial connection, the data are sent one bit at a time over the transmission channel. However, since most processors process data in parallel, the transmitter needs to transform incoming parallel data into serial data and the receiver needs to do the opposite. 
    Serial connection



    These operations are performed by a communications controller (normally aUART (Universal Asynchronous Receiver Transmitter) chip). The communications controller works in the following manner:
    • The parallel-serial transformation is performed using a shift register. The shift register, working together with a clock, will shift the register (containing all of the data presented in parallel) by one position to the left, and then transmit the most significant bit (the leftmost one) and so on:


    parallel-serial transformation

    • The serial-parallel transformation is done in almost the same way using a shift register. The shift register shifts the register by one position to the left each time a bit is received, and then transmits the entire register in parallel when it is full:


    serial-parallel transformation

    Synchronous and asynchronous transmission

    Given the problems that arise with a parallel-type connection, serial connections are normally used. However, since a single wire transports the information, the problem is how to synchronize the transmitter and receiver, in other words, the receiver can not necessarily distinguish the characters (or more generally the bit sequences) because the bits are sent one after the other. There are two types of transmission that address this problem:
    • An asynchronous connection, in which each character is sent at irregular intervals in time (for example a user sending characters entered at the keyboard in real time). So, for example, imagine that a single bit is transmitted during a long period of silence... the receiver will not be able to know if this is 00010000, 10000000 or 00000100...

    To remedy this problem, each character is preceded by some information indicating the start of character transmission (the transmission start information is called a START bit) and ends by sending end-of-transmission information (called STOP bit, there may even be several STOP bits).
    • In a synchronous connection, the transmitter and receiver are paced by the same clock. The receiver continuously receives (even when no bits are transmitted) the information at the same rate the transmitter send it. This is why the transmitter and receiver are paced at the same speed. In addition, supplementary information is inserted to guarantee that there are no errors during transmission.



    During synchronous transmission, the bits are sent successively with no separation between each character, so it is necessary to insert synchronization elements; this is called character-level synchronization
    The main disadvantage of synchronous transmission is recognising the data at the receiver, as there may be differences between the transmitter and receiver clocks. That is why each data transmission must be sustained long enough for the receiver to distinguish it. As a result, the transmission speed can not be very high in a synchronous link.

      List of relational database management systems

       

      List of relational database management systems


      SUBWAY SURFERS PARIS WITH UNLIMITED COINS AND KEYS

      SUBWAY SURFERS PARIS V 1.12 APK 
            WITH UNLIMITED COINS AND KEYS :) :)






      DASH as fast as you can!
      DODGE the oncoming trains!


      Help Jake, Tricky & Fresh escape from the grumpy Inspector and his dog.


      ★ Grind trains with your cool crew! 1
      ★ Colorful and vivid HD graphics!
      ★ Hoverboard Surfing!
      ★ Paint powered jetpack!
      ★ Lightning fast swipe acrobatics!
      ★ Challenge and help your friends!

      Join the most daring chase!

      A Universal App with HD optimized graphics.
      By Kiloo Games and Sybo Games


      RATING:  4.7/5.0    
      (1,517,948)

      CURRENT VERSION:   1.12.2

      REQUIRES ANDROID:   2.3.3 and up

      CATEGORY:    Arcade & Action

      INSTALLS:    50,000,000 - 100,000,000


      Download Link is HERE folks////.........       

      link1


      If the any irrelevant pages opened while downloading, Please refresh the hosting page and try again...

      Please inform us through your comments, if the download links are dead...

      Thank You....




      JETPACK JOYRIDE

      JET PACK JOYRIDE APK V 1.3.6 FREE DOWNLOAD





      ENJOY THE MOST PLAYED GAME IN RECENT TIMES...


      You're going for a ride - from the creators of FRUIT NINJA! One of the hottest mobile games in the world is now available free on Google Play!


      ** Winner **

      - Pocket Gamer - Best Action/Arcade Game 2012

      - Pocket Gamer - Overall Game of the Year 2012

      - Gamasutra Mobile Game of 2011

      - Game Revolution Best Mobile Game 2011

      ****


      Suit up with a selection of the coolest jetpacks ever made and take to the skies as Barry Steakfries, the lovable hero on a one-way trip to adventure! From the creators of the worldwide phenomenon Fruit Ninja comes the action-packed Jetpack Joyride, Halfbrick's most anticipated Android game ever!


      ****

      "Jetpack Joyride is, quite simply, an amazing game." -- IntoMobile


      "Like all the best mobile games, Jetpack Joyride is criminally simple." -- Kotaku


      “A miracle, by all accounts.” - PocketGamer

      ****


      Join Barry as he breaks in to a secret laboratory to commandeer the experimental jetpacks from the clutches of science evildoers. After lift-off, simply touch the screen to ascend and release to descend, raining bullets, bubbles, rainbows and lasers downwards as you fly towards higher and higher scores!


      You'll start off with the legendary Machine Gun Jetpack to scatter the evil scientists of Legitimate Research, but throughout each game you'll collect coins and complete missions to earn cash and buy new gear in The Stash! Pick your favorite jetpack, snazzy outfit and stock up on items then get back out there!


      Get a boost of speed and power using the Lil' Stomper, Profit Bird and Crazy Freaking Teleporter, just a selection of the vehicles pickups available - all playable with one touch controls.


      Stay alive, get funky and lose yourself in Jetpack Joyride. There's so much to see and do, all the time in the world and more than enough jetpacks! As always, Barry Steakfries will provide!


      ****


      Due to technical limitations, any device with 1000Mhz or less will be unable to run Jetpack Joyride. Halfbrick endeavors to support the lowest OS possible to provide as many people as we can, the opportunity to enjoy our games. Currently, we support OS v2.2 and above!


      Devices we do not support include:

      HTC Wildfire S

      Huawei M865

      Samsung Galaxy Mini

      LG Optimus One

      HTC myTouch 3G Slide

      HTC Explorer

      ZTE X500

      Samsung Replenish

      LG Ally

      Samsung Dart


      DOWNLOAD HERE :

      JetpackJoyRide.apklink1

      If the any irrelevant pages opened while downloading, Please refresh the hosting page and try again...

      Please inform us through your comments, if the download links are dead...

      Thank You....


      User Datagram Protocol (UDP)




      User Datagram Protocol (UDP) 


      User Datagram Protocol (UDP) is a TCP/IP standard defined in RFC 768, "User Datagram Protocol (UDP)." UDP is used by some programs instead of TCP for fast, lightweight, unreliable transportation of data between TCP/IP hosts.
      UDP provides a connectionless datagram service that offers best-effort delivery, which means that UDP does not guarantee delivery or verify sequencing for any datagrams. A source host that needs reliable communication must use either TCP or a program that provides its own sequencing and acknowledgment services.
      UDP messages are encapsulated and sent within IP datagrams, as shown in the following illustration.


       


       

      UDPServer.java:






























      import java.io.*;
      import java.net.*;

      class UDPServer
      {
         public static void main(String args[]) throws Exception
            {
               DatagramSocket serverSocket = new DatagramSocket(9876);
                  byte[] receiveData = new byte[1024];
                  byte[] sendData = new byte[1024];
                  while(true)
                     {
                        DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
                        serverSocket.receive(receivePacket);
                        String sentence = new String( receivePacket.getData());
                        System.out.println("RECEIVED: " + sentence);
                        InetAddress IPAddress = receivePacket.getAddress();
                        int port = receivePacket.getPort();
                        String capitalizedSentence = sentence.toUpperCase();
                        sendData = capitalizedSentence.getBytes();
                        DatagramPacket sendPacket =
                        new DatagramPacket(sendData, sendData.length, IPAddress, port);
                        serverSocket.send(sendPacket);
                     }
            }
      }
      UDPClient.java:

      import java.io.*;
      import java.net.*;

      class UDPClient
      {
         public static void main(String args[]) throws Exception
         {
            BufferedReader inFromUser =
            new BufferedReader(new InputStreamReader(System.in));
            DatagramSocket clientSocket = new DatagramSocket();
            InetAddress IPAddress = InetAddress.getByName("localhost");
            byte[] sendData = new byte[1024];
            byte[] receiveData = new byte[1024];
            String sentence = inFromUser.readLine();
            sendData = sentence.getBytes();
            DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, 9876);
            clientSocket.send(sendPacket);
            DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
            clientSocket.receive(receivePacket);
            String modifiedSentence = new String(receivePacket.getData());
            System.out.println("FROM SERVER:" + modifiedSentence);
            clientSocket.close();
         }
      }
            String sentence = inFromUser.readLine();
            sendData = sentence.getBytes();
            DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, 9876);
            clientSocket.send(sendPacket);
            DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
            clientSocket.receive(receivePacket);
            String modifiedSentence = new String(receivePacket.getData());
            System.out.println("FROM SERVER:" + modifiedSentence);
            clientSocket.close();
         }
      }

      Web Statistics