One thread can be used for each subtask.
We are dealing with concurrent processes
suppose parallel
write program with this in mind
(for organization and to capture concept)
For example, consider that reasoning methods may be categorized into types such as
Consider
Are there precedence constraints?
Precedence on the data...
If there are few such constraints, one could write a largely parallel algorithm. Often there are such constraints.
At a quite abstract level:
In any communication (man to man, machine to machine, man to machine), we have protocols. In the past, machines have been sequential single processors. When they have the ability to do more than one thing at once, what new things can they do? Do we still need to tell them what to do? How much can they do on their own?
In artificial intelligence we have the idea of intelligent agents and a blackboard. (their monitor) (consider implementation tools of Java Spaces and heredown for image)
Blackboard models usually consist of three components
The problem solving state data is kept in a global data base, the
blackboard. Knowledge sources produce changes to the blackboard which lead
incrementally to a solution to the problem. Communication and interaction
among the knowledge sources take place soley through the blackboard.
For control, the knowledge sources respond opportunistically to changes
in the blackboard.
What does this mean? Changes to the blackboard trigger knowledge source
activity.
Knowledge sources can be schematized as condition-action pairs.
The condition and action components of a KS are realized as arbitrary methods.
To minimize reevaluating the condition programs continuously, each condition
program declares to the system the primitive kinds of situations in which it is
interested. The condition method is triggered only when there occurs changes
that create such situations (and is then given references to all of them).
This changes a polling action into an interrupt-driven one and is more
efficient.
When executed, the condition method can search among the set of existing
hypothetical interpretations for arbitrarily complex configurations of interest
to its KS
See Hearsay-II pg 219
various ideas -
More computer science concrete: Dealing with resources
I am taking some of this out of
Operating System Concepts, Peterson and Silberschatz
A sequential program can be in one of four states:
We, of course want to prevent or avoid deadlock. If one has precedence
constraints, then whether you process in parallel or sequentially, you still
need to deal with this.
The Critical Section Problem
A critical section is a section of code that must be allowed to complete
atomically with no interruption that affects its successful completion or the
data it is working on. Such things as context switching a thread or updating
a record in a database are critical sections. Other things may go on at the
same time, and the thread that is executing in the critical section may even
lose its processor, but no other thread may do anything that affects the
critical section. Should another thread want to execute that same critical
section, it is forced to wait until the first thread finishes.
Critical sections are typically made as short as possible and often carefully
optimized because they can significantly affect the concurrency of the program. They are often used to
prevent data corruption of shared resources.
Synchronization mechanisms:
Two main functions with respect to shared resources:
note that resources can be almost anything
(e.g., an instance of something)
Monitor also has the shared object (or data members). If one can have multiple threads accessing data simultaneously, all shared data must be locked
and provide synchronized methods to provide access to the object. This
synchronization is vital to maintaining the integrity of any shared objects.
Consider - why isn't synchronized stuff in resources? (Usually if one takes
time to think about these things they make sense.)
Example Resources :
Monitors typically WAIT, SIGNAL, QUEUE
Another smaller scale example involves separate windows on a workstation.
One window could be used for input of information (the producer) and
another wiindow could react to that information (the consumer).
Mutual Exclusion
if a process is executing in its critical section then no other process
can be executing in its critical section
The Dining Philosophers Problem: Dijkstra (page 347)
The problem: deadlock. Suppose all pick up the right chopstick at the same
time. These hardworking philosophers could starve to death
Some possible solutions for you to implement Why did I even bring this up? communication, Shared memory
and synchronization. SUN and Java now have Jini, Java Spaces and Java Message Services to work with these ideas as well.
Controlling thread order - the Scheduler
Priorities:
Synchronization in Java is about 5 times more expensive to call. Use
sparingly.
Figure for state diagram of a process (page 320)
For us in java, a critical section is the same
as a synchronized method or block.
Monitor - If one wants concurrent processes then you need to keep the
resources and the monitor separate.
Appropriate monitor operations must be involved before and after resource
access Producer/consumer programs often employ remote monitoring, which allows
the consumer to watch a producer thread interacting with a user or some other
part of the system, For example, in a network, a group of producer threads
could be set to run on every workstation. The producers could print
documents, and as each document printed, a log entry could be stored. A
consumer (or multiple consumers) could then process the log and turn out
nightly reports of the day's printing activity.
Five philosophers spend their lives thinking and eating. The philosophers
share a common circular table surrounded by five chairs, each belonging
to one philosopher. In the center of the table there is a bowl of rice,
and the table is laid with five chopsticks. When a philosopher thinks,
he does not interact with his colleagues. From time to time, a philosopher
gets hungry and tries to pick up the two chopsticks that are closest to him
(the chopsticks that are between him and his left and right neighbors).
A philosopher may only pick up one chopstick at a time. Obviously, he
cannot pick up a chopstick that is already in the hand of a neighbor.
When a hungry philosopher has both his chopsticks at the same time, he eats
without releasing his chopsticks. When he is finished eating, he
puts down both of his chopsticks and starts thinking again.
(page 367 and 372 Java in 21 days)
setPriority - from 0 to 10