{"id":1802,"date":"2023-11-29T16:45:13","date_gmt":"2023-11-29T15:45:13","guid":{"rendered":"http:\/\/oopm.org\/?page_id=1802"},"modified":"2025-01-19T11:38:46","modified_gmt":"2025-01-19T10:38:46","slug":"8-1-a-simple-search-system","status":"publish","type":"page","link":"https:\/\/oopm.org\/?page_id=1802","title":{"rendered":"13.1 A simple search system"},"content":{"rendered":"<div class=\"pdfprnt-buttons pdfprnt-buttons-page pdfprnt-top-right\"><a href=\"https:\/\/oopm.org\/index.php?rest_route=wpv2pages1802&print=pdf\" class=\"pdfprnt-button pdfprnt-button-pdf\" target=\"_blank\"><img decoding=\"async\" src=\"https:\/\/oopm.org\/wp-content\/plugins\/pdf-print\/images\/pdf.png\" alt=\"image_pdf\" title=\"View PDF\" \/><\/a><a href=\"https:\/\/oopm.org\/index.php?rest_route=wpv2pages1802&print=print\" class=\"pdfprnt-button pdfprnt-button-print\" target=\"_blank\"><img decoding=\"async\" src=\"https:\/\/oopm.org\/wp-content\/plugins\/pdf-print\/images\/print.png\" alt=\"image_print\" title=\"Print Content\" \/><\/a><\/div>\n<p class=\"wp-block-paragraph\">As a first simple example, we will consider a problem in the domain of searching. Suppose we have an array of 150.000 records with people. We want to find all persons with an age between 18 and 24. We may do this by writing a method that goes through all the records and check the ages. We may also split the task into three tasks and define three activities where each activity handles one third of the records. This should speed up the process, compared to using just one activity.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The basic elements of a parallel system are objects executing computations in parallel &#8211; called <em>active objects<\/em>. Below we show how the the model of the search-activity may be split between active objects:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>aSimpleSearcher: <strong>obj<\/strong> BasicSystem\n   searcherA: <strong>obj<\/strong> BasicProcess \n      search(1,50000) \n   searcherB: <strong>obj<\/strong> BasicProcess\n      search(50001,100000)\n   searcherC: <strong>obj<\/strong> BasicProcess\n      search(10001,150000)\n   :::\n   searcherA.start\n   searcherB.start\n   searcherC.start<\/code><\/pre>\n\n\n\n<style>\n#XXXq {\n  width: 30%;\n  padding-left: 15px;\n  margin-left: 15px;\n   float: right;\n  background-color: lightgray;\n  font-size: 0.75em;\n}\n<\/style>\n<div id=\"XXXq\">To simplify the example, we assume that we have 150000 records. In general, it is not a good idea to encode constants like this in the code. Instead such values should be a parameter of a class or method or being read as data from some source.<\/div>\n\n\n\n<p class=\"wp-block-paragraph\">The object <code>aSimpleSearcher<\/code> is subclassed from a class <code>BasicSystem<\/code>, which is a class that defines abstractions for describing objects that may execute in parallel. One of these abstractions is class <code>BasicProcess<\/code>, which may be used as a superclass for objects that execute in parallel. We supply the details of <code>BasicSystem<\/code> in a later chapter.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>class<\/strong> BasicSystem:  \n   <strong>class<\/strong> BasicProcess: \n      start: :::\n      :::\n   ::: <\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The object <code>aSimpleSearcher<\/code> contains three searcher-objects, <code>searcherA<\/code>, <code>searcherB<\/code>, and <code>searcherC<\/code> which all are derived from <code>BasicProcess<\/code>. This means that they may execute in parallel. The execution of the three searcher-objects is started by invocation of the <code>start<\/code> method of class <code>BasicProcess<\/code>: <code>searcherA.star<\/code>t, etc. They all invoke a <code>search<\/code>-method on their third of the list of records. The <code>search<\/code>-method searches the range of objects within the arguments of <code>search<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Next we supply the details of the searching activity, that is the method <code>search<\/code> &#8211;<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-foreground-color\"> <\/mark>we assume that we have a class <code>Person<\/code> with a <code>name<\/code> and an <code>age<\/code> attribute:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>aSimpleSearcher: <strong>obj<\/strong> BasicSystem\n   records: <strong>obj<\/strong> Array(150000, Person)\n   search(first, last: <strong>var<\/strong> integer):\n      for (first):to(last):repeat\n          if ((18 &lt;= records&#91;inx].age) \n              and (records&#91;inx].age &lt;= 24)) :then\n             collector.insert(records&#91;inx])\n   collector: <strong>obj<\/strong> :::\n   :::\n<strong>class<\/strong> Person:\n   name: <strong>var<\/strong> String\n   age: <strong>var<\/strong> integer\n   ... <\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The object <code>aSimpleSearcher<\/code> has a local array, <code>records<\/code>, which is an array containing <code>150000<\/code> <code>Person<\/code>-objects. The method <code>search<\/code> searches the part of the array as defined by its parameters <code>first<\/code> and <code>last<\/code>. If a record matches the search-criteria, the <code>Person<\/code>-object is added to a <code>collector<\/code>-object.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Note: The class <code>BasicSystem<\/code> is placed within a module as described in chapter <script>mkRef(\"Modules\");<\/script> later in this chapter. This will require a minor adjustment to this example in order to be able to execute it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>collector<\/code>-object is a <code>Set<\/code>-object:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>collector: <strong>obj<\/strong> Set(Person)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><em>This looks simple and straightforward, but we have now arrived at one of the major problems in making parallel programs.<\/em> Since the three searcher-objects execute in parallel, two or more of them may invoke <code>collector.insert<\/code> at the same time. This may imply that the result of <code>collector.insert<\/code> has an unexpected result. The problem may be the implementation of the <code>insert<\/code> method of <code>Set<\/code>. As we shall see in a later chapter, <code>insert<\/code> manipulates local references in <code>Set<\/code>. This may not work if two or more <code>searcher<\/code>-objects does this at the same time.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Race conditions<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">This problem of two or more parallel objects accessing the same objects at the same time is referred to as a <em>race condition<\/em>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Race conditions may also appear in real life. One example is booking of hotel rooms: A customer may call a hotel and talk to a receptionist and ask for the booking a room on a specific date &#8211; it turns out that there is just one available room at that date. While the receptionist talks with the customer another potential customer calls the hotel and another receptionist answers the phone and it turns out that this customer also wants a room on the same day as the first customer.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The two receptionist can of course not both sell the same room, so in practice they have a means for avoiding this. In the old days they had a book where they recorded reservations and before making a reservation, a receptionist must get this book and only one can have the book at a given time. This ensures that a given room can only be booked once. Today most hotels have a computer system that takes care of reservations and avoiding race conditions.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Avoiding race conditions is a critical issue in parallel programming. For parallel programming the <code>Set<\/code> object, <code>collector<\/code>, used in the above example, plays a similar role to the reservation book of the hotel. At most one parallel object at a time may control <code>collector<\/code> just as at most one receptionist may control the reservation book. In the next section, we introduce a language mechanism that makes it possible to avoid race conditions.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The monitor system<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">There exists a number of language mechanisms that may help avoiding race conditions. In this section we use a <em>monitor<\/em> to define a safe version of <code>Collector<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A monitor is an object where it is only possible to invoke at most one method at a given time. That is two or more methods cannot be invoked at the same time. A new class <code>MonitorProcess<\/code> is defined to represent parallel activity that makes use of <code>Monitor<\/code> objects.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Class <code>Monitor<\/code> and class <code>MonitorProcess<\/code> are defined as part of the class <code>MonitorSystem<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>class<\/strong> MonitorSystem:\n   <strong>class<\/strong> MonitorProcess: BasicProcess\n      start: :::\n      :::\n   <strong>class<\/strong> Monitor: \n      entry:\n         :::\n   :::<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Class <code>Monitor<\/code> has a local method <code>entry<\/code> that must be used as a supermethod of all methods defined within in a subclass of <code>Monitor<\/code>. Only one method that has <code>entry<\/code> as a supermethod can be executed at a given time. For methods that have <code>entry<\/code> as supermethod, only one can be executed at a given time.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Note: As for <code>BasicSystem<\/code>, class <code>MonitorSystem<\/code> is placed within a module as described in chapter <script>mkRef(\"Modules\")<\/script> and this will also require a minor adjustment to this example in order to be able to execute it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We may now define the <code>collector<\/code> object as a <code>Monitor<\/code> by encapsulating the <code>Set<\/code>-object within the <code>Monitor<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>collector: <strong>obj<\/strong> Monitor\n   insert(p: <strong>ref<\/strong> Person): entry\n      matches.insert(p)\n   matches: <strong>obj<\/strong> Set(Person)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">As can be seen, <code>collector<\/code> is subclassed from <code>Monitor<\/code> and <code>insert<\/code> is a submethod of <code>entry<\/code>. This guarantees that at most one invocation of <code>insert<\/code> may be executed at a given time even though it may be called in parallel by the three searcher processes.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A <code>MonitorProcess<\/code> in a <code>MonitorSystem<\/code> can only acces data-items defined <em>locally<\/em> in the <code>MonitorProcess<\/code> object, but it may invoke methods of a <code>Monitor<\/code> object. The reason for this is to avoid race conditions if two or more <code>MonitorProcess<\/code> object access the same objects at the same time.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In the simple searcher, the objects to be searched are in the <em>global<\/em> object <code>records<\/code>. This objects can thus not be accessed by a <code>MonitorProcess<\/code> object. We thus have to organize the records in another way.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this simple example, we split the <code>records<\/code> array object into three array objects and place one in each searcher object. We define a general <code>Searcher<\/code> class that contains the <code>records<\/code> and the search method of a given <code>MonitorProcess<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>class<\/strong> Searcher: MonitorProcess\n   records: <strong>obj<\/strong> Array(50000, Person)\n   search(first, last: <strong>var<\/strong> integer):\n      -\"-\n   inner(Searcher)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">We may now define the searcher objects as subclassed from <code>Searcher<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>searcherA: <strong>obj<\/strong> Searcher \n    search(1,50000) \nsearcherB: <strong>obj<\/strong> Searcher\n   search(1,50000)\nsearcherC: <strong>obj<\/strong> Searcher\n   search(1,50000)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In this way each <code>Searcher<\/code> object has its own <code>records<\/code> to be searched.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>search<\/code> methods defined above is the same as the one defined in the <code>aSimpleSearcher<\/code>. The difference is that here it is placed locally to the three <code>searcher<\/code>-objects. Each of them has its own <code>search<\/code> method although the code is identical and defined in class <code>Searcher<\/code>, which is a superclass of all three objects.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We now add a <code>MonitorProcess<\/code>-object that presents the results of the searching. Such a <code>MonitorProcess<\/code> has to wait for all three <code>Searcher<\/code>-objects to have finished searching their part of the objects.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>presenter: <strong>obj<\/strong> MonitorProcess\n   waitTermination(searcherA, SearcherB, SearcherC)\n   collector.scan\n      console.print(\"Found\" + current.asText)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The method <code>waitTermination<\/code> waits until all its arguments <code>searcherA<\/code>, <code>SearcherB<\/code>, and <code>SearcherC<\/code> have terminated execution.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A <code>scan<\/code>-method has been added to <code>collector<\/code>. It scans though all elements in the set of matches, and execute an <code>inner<\/code> for each element:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>collector: <strong>obj<\/strong> Monitor\n   -\"-\n   scan:\n      current: <strong>ref<\/strong> Person\n      matches.scan\n           this(scan).current := current\n           inner(scan)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The complete system then consists of the following elements:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>aSafeSearcher: <strong>obj<\/strong> MonitorSystem \n   <strong>class<\/strong> Searcher: -\"-\n   searcherA: <strong>obj<\/strong> Searcher \n      search(1,50000) \n   searcherB: <strong>obj<\/strong> Searcher\n      search(1,50000)\n   searcherC: <strong>obj<\/strong> Searcher\n      search(1,50000)\n   collector: <strong>obj<\/strong> Monitor \n      insert(P: <strong>ref<\/strong> Person): entry\n         -\"-\n      scan:\n         -\"-\n      matches: <strong>obj<\/strong> Set(Person)\n   presenter: <strong>obj<\/strong> MonitorProcess\n      -\"-\n   searcherA.start\n   searcherB.start \n   searcherC.start\n   presenter.start\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">As being said before, most of the examples in this book is for illustrating basic programming and modelling. In this example we have not dealt with how to add content to the records of the <code>Searcher<\/code> object. Also organizing the records as done here may not be the best solution in a practical system.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Using a bounded buffer<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Computers in general have limited storage with respect to RAM and disk space, and programs have to take this into account. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The next example is also in the domain of searching. We consider a number of clients that makes requests to a server for searching <code>Person<\/code>-objects with specific values of its attributes, such as <code>name<\/code> and <code>age<\/code> above.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The overall structure of this system is:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>usingBoundedBuffer: <strong>obj<\/strong> MonitorSystem\n   <strong>class<\/strong> Client: MonitorProcess\n      mkRequest(field: <strong>var<\/strong> String, V: <strong>var<\/strong> String) -&gt; R: <strong>ref<\/strong> Request:\n         :::\n   <strong>class<\/strong> Request(sendedr: <strong>ref<\/strong> Client, field: <strong>var<\/strong> String, V: <strong>var<\/strong> String):\n      :::\n      ...\n   clientA: <strong>obj<\/strong> Client(\"clientA\")\n      :::      \n   clientB: <strong>obj<\/strong> Client(\"clientB\")\n      :::\n   clientC: <strong>obj<\/strong> Client(\"clientC\")\n      :::\n\n   server: <strong>obj<\/strong> Monitor\n      addRequest(R: <strong>ref<\/strong> Request): entry\n         :::\n      getRequest -&gt; R: <strong>ref<\/strong> Request: entry\n         :::\n      requests: <strong>obj<\/strong> BoundedBuffer(#Request,100)\n\n   Searcher: MonitorProcess\n      decodeAndSearch(R: <strong>ref<\/strong> Request):\n         ...\n      :::\n   searcherA: <strong>obj<\/strong> Searcher(\"searcherA\")\n   searcherB: <strong>obj<\/strong> Searcher(\"searcherB\")\n   searcherC: <strong>obj<\/strong> Searcher(\"searcherC\")<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The following code defines a class <code>Client<\/code> that may be used to specify the clients of the system:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>class<\/strong> Client: MonitorProcess\n   mkRequest(field, value: <strong>var<\/strong> String) -&gt; R: <strong>ref<\/strong> Request:\n      R := Request(this(Client),field, value)\n      server.addRequest(r)\n   inner(Client)\n<strong>class<\/strong> Request(sender: <strong>ref<\/strong> Client, field, V: <strong>var<\/strong> String):\n   ...\nclientA: <strong>obj<\/strong> Client\n   mkRequest(\"age\",\"18-24\")\n   mkRequest(\"name\",\"John Smith\")\n   ...\nclientB: <strong>obj<\/strong> Client\n   mkRequest(\"age\",\"60-65\")\n   ...\nclientC: <strong>obj<\/strong> Client\n   ...<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Class <code>Client<\/code> describes the general structure of a client submitting request to the <code>server<\/code>. <\/li>\n\n\n\n<li>Class <code>Request<\/code> describes the structure of a request. It contais the <code>sender<\/code> of the <code>Request<\/code>, a <code>field<\/code> holding the name of the attribute to search for, and a parameter <code>V<\/code> holding the value (or interval of values) that must match the <code>field<\/code>.<\/li>\n\n\n\n<li>The method <code>mkRequest<\/code> creates a <code>Request<\/code> and sends it to the server using <code>server.addRequest(R)<\/code>.<\/li>\n\n\n\n<li>Three sub of <code>Client<\/code>, <code>clientA<\/code>, <code>clientB<\/code>, and <code>clientC<\/code> subclassed from <code>Client<\/code> are declared, each submitting different requests.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">We  implement the server as a <code>Monitor<\/code> that keeps track of the various requests.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>server: <strong>obj<\/strong> Monitor\n   addRequest(R: <strong>ref<\/strong> Request): entry\n      request.insert(R)\n   getRequest -&gt; R: <strong>ref<\/strong> Request: entry\n      R := requests.next\n   requests: <strong>obj<\/strong> BoundedBuffer(100,Request)\n   :::<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The method <code>addRequest<\/code>, inserts the <code>Request<\/code> <code>R<\/code> in the array <code>requests<\/code>. <\/li>\n\n\n\n<li>The method <code>getRequest<\/code> is used by a searcher to get a request. The <code>requests<\/code>-object is of type <code>BoundedBuffer<\/code>, which is a list where a limited number of objects may be stored &#8211; in this case 100.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">We have to define a new version of a searcher-object to be used in this example since the searching is more complicated than just searching for a person with an age between 18 and 24.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>class<\/strong> Searcher: MonitorProcess\n   decodeAndSearch(R: <strong>ref<\/strong> Request):\n      ...\n   cycle\n      R: <strong>ref<\/strong> Request\n      R := server.getRequest\n      decodeAndSearch(R)\n\nsearcherA: <strong>obj<\/strong> Searcher\nsearcherB: <strong>obj<\/strong> Searcher\nsearcherC: <strong>obj<\/strong> Searcher<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">A <code>Searcher<\/code>-process retrieves a request from the <code>Server<\/code>. It then has to decode the data-items <code>field<\/code> and <code>V<\/code> to find out what to search for. This is done by the method <code>decodeAndSearch<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For a request with <code>field = \"age\" <\/code>and <code>V = \"60-65\"<\/code>, it must read the string <code>field<\/code> to find out that it is the <code>age<\/code> attribute that is to be used in the search. And it must decode the <code>String<\/code> &#8220;60-65&#8221; to find out that the age must be between 60 and 65. Finally the search method above must have the ages to search for defined as parameters. We don&#8217;t show the details here.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For a request with <code>field = \"name\"<\/code> and <code>\"V = \"John Smith\"<\/code>, a similar decision must be made and another search-method must be written to search for <code>Person<\/code>-objects where the <code>name<\/code>-attributes has the given value. Again we don&#8217;t show the details.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Handling the capacity of the server<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">As mentioned, the <code>Server<\/code> stores the request in the <code>requests<\/code>-object, which can hold a maximum of 100 objects. A client trying to add a <code>Request<\/code> must therefore check if the buffer is not full, and if it is, wait until some space is available.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The same is the case for a <code>Searcher<\/code>-object. When calling <code>getRequest<\/code>, the <code>requests<\/code>-buffer may be empty and thus no <code>Request<\/code> can be returned to the <code>Searcher<\/code>. In this case the method <code>getRequest<\/code> must wait until a client inserts a <code>Request<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To handle this, a <code>Monitor<\/code>-object has a method <code>wait<\/code> that delays execution of an <code>entry<\/code>-method until a given condition becomes true:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>wait(condition)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">We may use <code>wait<\/code> in the <code>server<\/code>-object as follows:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>server: <strong>obj<\/strong> Monitor\n   addRequest(R: <strong>ref<\/strong> Request): entry\n      wait(not requests.full)\n      request.insert(R)\n   getRequest -&gt; R: <strong>ref<\/strong> Request: entry\n      wait(not requests.isEmpty)\n      R := requests.next\n   requests: <strong>obj<\/strong> BoundedBuffer(100,Request)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In the beginning of the <code>addRequest<\/code>-method, a <code>wait(not requests.full) <\/code>is inserted. The invocation <code>requests.full <\/code>returns true if the buffer is full. The method wait simply delays the execution of <code>addRequest<\/code> until the buffer is not full. This may happen if a <code>Searcher<\/code>-object removes a <code>Request<\/code> using getRequest.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In a similar way, a <code>wait(not requests.isEmpty)<\/code> is inserted in the beginning of <code>getRequest<\/code>. It delays execution of <code>getRequest<\/code> until the buffer is not empty.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Organization of BasicSystem and MonitorSystem<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In this section, we describe how the classes <code>BasicSystem<\/code> and <code>MonitorSystem<\/code> are organized in modules . This is of course necessary to understand in order to be able to executed the above programs.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Class <code>BasicSystem<\/code> is placed within the module <code>BasicSystemLib<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>BasiSystemLib: <strong>obj<\/strong>\n   <strong>class<\/strong> BasiscSystem:\n      <strong>class<\/strong> BasicProcess:\n         :::<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Class <code>MonitorSystem<\/code> is similar within a module <code>MonitorSystemLib<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>MonitorSystem: <strong>obj<\/strong> BasicSystemLib.BasicSystem\n   <strong>class<\/strong> MonitorSystem:\n      <strong>class<\/strong> MonitorProcess:\n         :::\n   <strong>   class<\/strong> Monitor:\n         :::<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The necessary adjustments to the above examples implies that the programs must be derived from class <code>BasicSystem<\/code> or class <code>MonitorSystem<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The program <code>aSimpleSearcher<\/code> must thus be derived from class <code>BasicSystemLib.BasicSystem<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>aSimpleSearcher: <strong>obj<\/strong> BasicSystemLib.BasicSystem\n   -\"-<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The program <code>aSafeSearcher<\/code> must be derived from class <code>MonitorSystemLib.MonitorSystem<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>aSafeSearcher: <strong>obj<\/strong> MonitorSystemLib.MonitorSystem\n   -\"-<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Finally, <code>usingBoundBuffer<\/code> must also be derived from class <code>MonitorSystemLib.MonitorSystem<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>usingBoundedBuffer: <strong>obj<\/strong> MonitorSystemLib.MonitorSystem\n   -\"-<\/code><\/pre>\n<div style=\"display:flex; gap:10px;justify-content:center\" class=\"wps-pgfw-pdf-generate-icon__wrapper-frontend\">\n\t\t<a  href=\"https:\/\/oopm.org?action=genpdf&amp;id=1802\" class=\"pgfw-single-pdf-download-button\" ><img src=\"https:\/\/oopm.org\/wp-content\/plugins\/pdf-generator-for-wp\/admin\/src\/images\/PDF_Tray.svg\" title=\"Generate PDF\" style=\"width:auto; height:45px;\"><\/a>\n\t\t<\/div>","protected":false},"excerpt":{"rendered":"<p>As a first simple example, we will consider a problem in the domain of searching. Suppose we have an array of 150.000 records with people. We want to find all persons with an age between 18 and 24. We may do this by writing a method that goes through all the records and check the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":1669,"menu_order":1,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-1802","page","type-page","status-publish","hentry"],"mb":[],"mfb_rest_fields":["title","gutenberg_elementor_mode"],"_links":{"self":[{"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages\/1802","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/oopm.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1802"}],"version-history":[{"count":95,"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages\/1802\/revisions"}],"predecessor-version":[{"id":11296,"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages\/1802\/revisions\/11296"}],"up":[{"embeddable":true,"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages\/1669"}],"wp:attachment":[{"href":"https:\/\/oopm.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1802"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}