Multi-Threaded #43

pulse

We saw how to Start( ) a thread and then Suspend( ) it. Why? Answer: so later on we can (in any point of time in the future) Resume this ready-to-go- thread without “paying” the initialization time. We saw the Pulse/Wait synchronization methodology.  How does it work? Answer: we can set one (or more) threads in a Wait( ) state (=blocking state) which will make the thread wait until a different thread calls the Pulse( ) method and releases the “waiting” thread. Pulse( ) will free only one Waiting thread. PulseAll( ) will free all of the Waiting threads. keep in mind that Wait/Pulse/PulseAll could only be called from a critical section in which is locked by the same key. In our example: we had a mobile technician department which are fixing phones, and a customer-service department which should call each customer after his phone has been fixed. Therefor, we had a thread in a Wait state (the customer-service), and a different thread for the technician which fixes the phone. after the technician completed to fix the phone- he Pulses the customer-service thread (which was in Wait state) – to release the thread and make him “call the customer”.

dp

What are design patterns? Answer: a software design pattern is a general, reusable solution to a commonly occurring problem within a given context in software design. It is a description or template for how to solve a problem that can be used in many different situations. Design patterns are formalized best practices that the programmer can use to solve common problems when designing an application or system. In the last part of the lesson we implemented the Singleton design pattern.

More topics covered:

  • Firing a thread in a Timer
  • Gang of Four

Links:

 

Leave a comment