From eb4161840396b65cb8e018db042eb8ae101b2646 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Wed, 1 Dec 2021 23:10:21 +0100 Subject: tsdwl: adds in java --- Year_3/TSDWL/ex_20191218/Thread2.java | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 Year_3/TSDWL/ex_20191218/Thread2.java (limited to 'Year_3/TSDWL/ex_20191218/Thread2.java') diff --git a/Year_3/TSDWL/ex_20191218/Thread2.java b/Year_3/TSDWL/ex_20191218/Thread2.java new file mode 100644 index 0000000..35cb3fe --- /dev/null +++ b/Year_3/TSDWL/ex_20191218/Thread2.java @@ -0,0 +1,28 @@ +public class Thread2 extends Thread { + Shared mem; + public Thread2(Shared mem) { + super(); + this.mem = mem; + } + + public void run() { + int m; + + while (true) { + try { + Thread.sleep(300); + } catch (InterruptedException e) { + e.printStackTrace(); + break; + } + synchronized(mem) { + if (mem.get() == -1) { + break; + } + + System.out.println("\t\t\tThread 2, notify thread 1"); + mem.notify(); + } + } + } +} -- cgit v1.2.3-18-g5258