This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
public class Publisher //main publisher class which will invoke methods of all subscriber classes | |
{ | |
public delegate void TickHandler(Publisher m, EventArgs e); //declaring a delegate | |
public TickHandler Tick; //creating an object of delegate | |
public EventArgs e = null; //set 2nd paramter empty | |
public void Start() //starting point of thread | |
{ | |
while (true) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.concurrent.Semaphore; | |
class Queue { | |
int value; | |
static Semaphore semProd = new Semaphore(1); //Producer is first getting lock on producer semaphore | |
static Semaphore semCon = new Semaphore(0); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.concurrent.*; | |
class Producer implements Runnable { | |
private BlockingQueue<Integer> queue; | |
Producer(BlockingQueue<Integer> q){ | |
this.queue=q; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
public class InterThreadCommunicationExample { | |
public static void main(String args[]) { | |
final LinkedList<Integer> sharedQ = new LinkedList<Integer>(); | |
Thread producer = new Producer(sharedQ); | |
Thread consumer = new Consumer(sharedQ); |