Jacketing

from Wikipedia, the free encyclopedia

Under Jacketing refers to the possibility of a blocking system call to get around.

A call is called blocking if it not only calculates, but instead waits until some event occurs and only then continues to work. In a system without multitasking this is fatal, the computer cannot be used until the event occurs. But even if multitasking is supported, a blocking function call can interfere. For example, the thread that keeps the graphical user interface up-to-date should respond promptly to user input.

Many system calls that access external devices are blocking.

Procedure for functions without a return value

If the blocking system call does not provide a return value, the call can be moved to a new thread, but the calling thread can continue to run at the same time.

Example in Smalltalk

As a class method of Object:

 unblock: selector
    "Macht den blockierenden Aufruf selector unblockierend."
    |bs|
    bs := (#blocking , selector) asSymbol. "Der alte Aufruf wird umbenannt"
    self
        addSelector: bs
              withMethod: (self methodAt: selector) ; removeSelector: selector.
    self addSelector: selector
        withMethod: (self class compile:
            '[self ', (self standardMethodHeaderFor: bs), '] fork')

Calling Test unblock: #tuWasthe method

 tuWas
       Transcript show: 'Yippie!'

by the two methods

 blockingtuWas
       Transcript show: 'Yippie!'

and

 tuWas
     [self blockingtuWas] fork

replaced.

The call tuWaswould now be completed in a few milliseconds, but the output on the transcript would come a little later.

Procedure for functions with a return value

If a blocking routine is to be called from a thread in which the result is also required, but not necessarily immediately, the above procedure is used again, but the blocking routine is changed so that it reports as soon as it has been processed. Communication between two processes can take place through a semaphore . The calling thread regularly listens to the semaphore for an answer. If so, he lets it be given to him and uses it. If not, he continues to calculate unmolested.

example

Be tuWasso a blocking call that a profit after a certain period ereturns. Until this is available, it should be self tuWasAnderesInDerZwischenzeitcarried out regularly

 |e s|
 s := Semaphore new.
 [e := self tuWas. s signal] fork.
 [self tuWasAnderesInDerZwischenzeit] doWhileFalse: [s isSignaled].
 "Hier steht e zur Verfügung"