# TEXT CODE STARTS HERE
# import threading module to use Semaphore
import threading
#import time to make thread sleep for specified time
import time
# create two semaphores sem1 and sem2
sem1 = threading.Semaphore()
sem2 = threading.Semaphore()
# defining method fun1() to run in thread t1
# thread t1 will try to acquire locks in order sem1 then sem2
def fun1():
# print some message about thread1
print("Thread1 started")
while True:
# acquire lock on sem1
sem1.acquire()
# make thread t1 to sleep for 1 sec.
time.sleep(1)
# qcquire lock on sem2
sem2.acquire()
# print string "THREAD1"
print("THREAD1")
# release lock on sem2
sem2.release()
# release lock on sem1
sem1.release()
# defining method fun1() to run in thread t2
# thread t2 will try to acquire locks in order sem2 then sem1
def fun2():
# print some message about thread2
print("Thread2 sarted")
while True:
# acquire lock on sem2
sem2.acquire()
# make thread t2 to sleep for 1 sec.
time.sleep(1)
# qcquire lock on sem1
sem1.acquire()
# print string "THREAD2"
print("THREAD2")
# release lock on sem1
sem1.release()
# release lock on sem2
sem2.release()
# create thread t1 with target method fun1
t1 = threading.Thread(target = fun1)
# start thread t1
t1.start()
# create thread t1 with target method fun1
t2 = threading.Thread(target = fun2)
# start thread t1
t2.start()
# TEXT CODE ENDS HERE
SCREENSHOTS:
code:


output ( Thread1 and Thread2 has successfully started but fall in deadlock ) :

NOTE:-

Give a programming example in python of a deadlock with semaphore lock. please include output screenshot.
Dining Philosophers Problem: I need explanation with the following implementation Starvation? Deadlock? Spin lock Semaphore with queues
Explain whether this code avoids deadlock and starvation. Give
detailed reasoning.
semaphore fork5-1 semaphore s ## 1 int i void philosopher(int ai) while(true) f think: wait (s); wait (forki); wait(forkfi +1 mod 5); signal(% eat ): wait(s); signal(fork]); signal(forkli +1] mod 5); signal(s):
Java programming
Exercise 32.11 Write a program that uses explicit locks (or semaphores) to cause a deadlock. Do not use the synchronized keyword. Repeatedly try to lock and unlock the locks and print messages to indicate when a lock is locked or unlocked to give some indication of what the program is doing. Using Thread.sleep) might be helpful to make a deadlock more likely.
Exercise 32.11 Write a program that uses explicit locks (or semaphores) to cause a deadlock. Do...
Programming in Java. Please attached the
screenshot of source code and the output Thanks.
Java Programming: A Comprehensive Introductia See this solution in the app :3 Chapter 3, Problem 17E Bookmark Show all steps: 0 ON Problem Write a program that uses a loop to print a list of 100 numbers consisting of alternating 1's and -1's, starting with 1.
Answer in python 3 and can you please include a screenshot of the code and the output Problem 4 (Quicksort) For this problem you must implement the recursive quicksort algorithm covered in lecture to sort points based on their distance from the point (0, 0). Crete a Python file called quicksort.py and implement a function called quicksort(list) that does the following: COMP 1005/1405A – S19 – A5 Due Saturday, June 15th at 11:59 PM 3 1. Takes a 2D list...
please post the screenshot of the output. I want to learn from
it
Using what you've learned about strings, variables, files, and dictionaries in Python, build a random plot/insult/anything generator (i.e. a script that each time you run it prints a different string related to a theme such as, for example, Shakespearean insults).
Programming logic C# visual studio. Please paste the code with the screenshot. Compute the average of the elements of the given array and then output the average. int[] numbers = new int[10]; Add these numbers to the array 87, 68, 94, 100 , 83, 78, 85, 91, 76, 87 The output should be like this: The average is ……
*** Please if you want to answere this question,
include your program output screenshot. And follow the requirements
please, thanks.****
Design a Java program: A JPanel of dimension 400 X 200. The
background is initially displayed as white and there is a line
drawn vertically half way through the screen. When a mouse is
clicked on the left hand side of the line, the position of the
click is shown with a small circle and the background changes to
yellow....
Code the following example and screenshot the text output.
After you have the test code working, modify it so that it has
the following features: ○ The ‘while’ loop is inside a try/except
error check. This allows a <CTRL>C to break out of the loop ○
Keep track of the number of button presses with an accumulator
variable ○ After the loop is ended with an exception, create an
attractive output which tells the user that the program has ended...
Python Programming please Write a piece of code that gets a string variable (IP) from the user (ex: “192.168.10.1”) and converts the decimal IP to binary mode. Output would be the octet in decimal format and next to it the octet in binary. Tip: Use the bin() built-in function. Example: Input: “192.168.10.1” Output: 192 – 11000000 10 – 10101000 10 – 00001010 1 – 00000001