QUESTION 2 (38 MARKS) Given the following code snippet. 16. 17. 18. 19. 20. 21. 22. 23. 24. 125. 26. 27. 28. 29. import threading global variable y y-D def increment (): global y for in zange (1000000): y +1 def main() global if tIncrment threading. Thread (target-increment) tIncrment2 threading.Thread(target-increment) tIncrment.atart() tIncrment2.start() tIncerment.join() Incrment2.join() name main() print (y) main": Determine how many processes and threads are in the given code. Determine the output of the given code and justify your answer. Identify the critical sections of the given code (4 markah/mark) Revise the threads) in the given code using process() (5 markah/marks) (2 markah/mark) Revise the code and apply mutual exclusion on the critical sections in the given code then write the output of the revised code (9 markah/mark) (7 markah/marks) Using the Clojure programming language, construct a new application and use atomic concepts to replace the given code (11 markah/marks)
QUESTION 2 (38 MARKS) Given the following code snippet. 2. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. import threading global variable y y=0 def increment (): global y for in range (1000000) : y +1 def main (): global x tIncrment= threading. Thread (target-increment) tIncrment2 = threading.Thread (target-increment) tIncrment.start() tIncrment2.start() tIncrment.join() tIncrment2.join() if name main () print (y) main ": Determine how many processes and threads are in the given code. Determine the output of the given code and justify your answer. (4 markah/marks) (5 markah/marks)
Identify the critical sections of the given code. (2 markah/marks) Revise the code and apply mutual exclusion on the critical sections in the given code, then write the output of the revised code. (9 markah/marks) Revise the thread(s) in the given code using process(s). (7 markah/marks) Using the Clojure programming language, construct a new application and use atomic concepts to replace the given code. (11 markah/marks)
QUESTION 2 (38 MARKS) Given the following code snippet. 16. 17. 18. 19. 20. 21. 22. 23. 24. 125. 26. 27. 28. 29. import
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am