relatively large blocks once the tape is moving similar conditions hold for magnetic diskswhere the data are allocated on tracks with fixed number of blocks of fixed sizethe so-called block size in facta disk should be regarded as an array of blockseach block being read or written as wholecontaining typically bytes with our programshoweverdo not observe any such timing constraints in order to allow them to ignore the constraintsthe data to be transferred are buffered they are collected in buffer variable (in main storeand transferred when sufficient amount of data is accumulated to form block of the required size the buffer' client has access only via the two procedures deposit and fetch definition bufferprocedure deposit (xchar)procedure fetch (var xchar)end buffer buffering has an additional advantage in allowing the process which generates (receivesdata to proceed concurrently with the device that writes (readsthe data from (tothe buffer in factit is convenient to regard the device as process itself which merely copies data streams the buffer' purpose is to provide certain degree of decoupling between the two processeswhich we shall call the producer and the consumer iffor examplethe consumer is slow at certain momentit may catch up with the producer later on this decoupling is often essential for good utilization of peripheral devicesbut it has only an effectif the rates of producer and consumer are about the same on the averagebut fluctuate at times the degree of decoupling grows with increasing buffer size we now turn to the question of how to represent bufferand shall for the time being assume that data elements are deposited and fetched individually instead of in blocks buffer essentially constitutes firstin-first-out queue (fifoif it is declared as an arraytwo index variablessay in and outmark the positions of the next location to be written into and to be read from ideallysuch an array should have no index bounds finite array is quite adequatehoweverconsidering the fact that elements once fetched are no longer relevant their location may well be re-used this leads to the idea of the circular buffer in out fig circular buffer with indices in and out the operations of depositing and fetching an element are expressed in the following modulewhich exports these operations as proceduresbut hides the buffer and its index variables -and thereby effectively the buffering mechanism -from the client processes this mechanism also involves variable counting the number of elements currently in the buffer if denotes the size of the bufferthe condition ((buffer non-empty)and the operation deposit by the condition (buffer non-fullnot meeting the former condition must be regarded as programming errora violation of the latter as failure of the suggested implementation (buffer too small