-2

I have a project for my operating systems class in which we need to write a program using multiple threads and no semaphores , i understand how to do it in pseudo code but as I'm thinking about implementation I can't figure out how to declare shared variable all I can think of is having another thread holding all shared variables Edit 1: to synchronize we have to use while(busywait true) {}

edit 2: Through its implementation, this project will familiarize you with the creation and execution of threads, and with the use of the Thread class methods. In order to synchronize the threads you will have to use (when necessary), run( ), start( ), currentThread( ), getName( ), join( ), yield( ), sleep(time), isAlive( ), getPriority( ), setPriority( ), interrupt( ), isInterrupted( ), maybe synchronized methods. In synchronizing threads, DO NOT use any semaphores. DO NOT use wait( ), notify( ) or notifyAll();

1 Answers1

0

Correct multithreading programming assumes using of some kind of synchronization facility. Any synchronization facility can be built only using another synchronization facility. The lowest level synchronization facility is a memory cell accessed with compare-and-set processor command. In Java, an equivalent to that command is AtomicInteger.compareAndSet​(int expectedValue, int newValue) and analogue methods of other atomic classes.

Alexei Kaigorodov
  • 13,189
  • 1
  • 21
  • 38