XML

kent logo

CO538 Anonymous Questions and Answers Keyword Index

This page provides a keyword index to questions and answers. Clicking on a keyword will take you to a page containing all questions and answers for that keyword, grouped by year.

To submit a question, use the anonymous questions page. You may find the keyword index and/or top-level index useful for locating past questions and answers.

Keyword reference for forking

2011

Question 53 (2011):

Submission reference: IN2085

Is there a way to run a one-off process in parallel with the execution of the currently running process in a "fire-and-forget" kind of way? I think my question may be clearer in code. Is there a way to do the following, as an example?:

    PROC b ()
      ...  do potentially long-winded stuff (possibly non-terminating)
    :

    PROC a ()
      WHILE TRUE
        SEQ
          IF
	    condition
	      b ()
	    TRUE
	      SKIP
          ...  do stuff
    :

Is there a way to start process b running, then in carry on doing a in parallel, while b finishes doing whatever it is that b does?

Answer 53:

Yes, there is! But we need FORKing – see Mobiles slides 102-106 and the example slides that follow.

For your example, you just need one new keyword:

    PROC b ()
      ...  do potentially long-winded stuff (possibly non-terminating)
    :

    PROC a ()
      WHILE TRUE
        SEQ
          IF
	    condition
	      FORK b ()
	    TRUE
	      SKIP
          ...  do stuff
    :

We don't have to have the FORKING block shown on slides 104-106. If we don't, the whole program is a default FORKING block – i.e. all FORKed process must terminate for the whole program to terminate. Explicit FORKING blocks control this with finer granularity.

If the FORKed process takes parameters, be aware of the different semantics when passing arguments to those parameters – they have the semantics of channel communcation (slides 105-106), rather than conventional parameter passing.

Note: a FORKed process must take parameters (e.g. shared and/or mobile channel-ends). Otherwise, there is no way anything it does can have any effect! FORKed processes cannot access globals (anything declared outside its PROC header).

Note: the material on forking is not part of the examinable material for this module.

Keywords: forking

Valid CSS!

Valid XHTML 1.0!

This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License.
Last modified Mon May 20 13:50:27 2013
This document is maintained by Fred Barnes, to whom any comments and corrections should be addressed.