SemaphoreDemo: Refactored.

This commit is contained in:
2024-02-26 10:24:01 +01:00
parent c06d174ee8
commit 7f80227ea6
4 changed files with 20 additions and 7 deletions

1
Technology/SemaphoreDemo/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/bin/

View File

@@ -1,5 +1,15 @@
// java program to demonstrate
// use of semaphores Locks
// Karsten Jeppesen, UCN
//
// java application to demonstrate
// use of semaphores (Locks)
//
// Semaphore methods:
// acquire()
// will wait for semaphore to be in released state. Will set semaphore to acquired state
// release()
// will release an acquired semaphore
import java.util.concurrent.*;
//A shared resource/class.

View File

@@ -1,5 +1,8 @@
// java program to demonstrate
// use of semaphores Locks
// Karsten Jeppesen, UCN
//
// java application to demonstrate
// use of semaphores (Locks)
import java.util.concurrent.*;
@@ -14,9 +17,7 @@ public class SemaphoreDemo
// A 0 means that you are not allowed to read (as nobody has yet written to the buffer)
Semaphore semCon = new Semaphore(0);
// creating two threads with name A and B
// Note that thread A will increment the count
// and thread B will decrement the count
// creating two threads named "Producer" and "Consumer"
MyThread mt1 = new MyThread(semPro, semCon, "Producer");
MyThread mt2 = new MyThread(semPro, semCon, "Consumer");