From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,a0224dc3d1e52f3d X-Google-Attributes: gid103376,public From: "James S. Rogers" Subject: Streams and Concurrency Date: 1998/12/30 Message-ID: <76c3tv$acs@bgtnsc02.worldnet.att.net>#1/1 X-Deja-AN: 426974884 Organization: AT&T WorldNet Services X-MimeOLE: Produced By Microsoft MimeOLE V4.72.2106.4 Newsgroups: comp.lang.ada Date: 1998-12-30T00:00:00+00:00 List-Id: A question was recently raised about task safe use of streams. A stream is just as safe in a concurrent design as any other shared resource. That is, unless it is properly protected, it is not at all safe. The same may be said of shared memory, or shared files. There are two classical solutions to this problem. The first is to elminate the shared resource, and have a single, unshared resource for each task. The second is to protect the shared resource by having only one task at a time access the resource. Classical database engines control concurrent access to the database by forcing all tasks to access the database through a single database engine. The same sort of thing can be achieved in Ada in a couple of ways. One way is to have all tasks send messages to a single controlling task through a rendezvous. This would be the typical Ada 83 approach. The more modern, and more efficient approach in Ada 95 is to have encapsulate the stream in a protected object. All access will be correctly and effectively controlled by the protected object mechanism. When you use a protected object the "read" and "write" procedures or entries must have a parameter of a class-wide type. The class-wide type parameter will allow the protected object to read and write a wide range of otherwise heterogeneous data items to and from the stream. The stream may simply be an instance of Ada.Streams.Stream_Io, or it may be a custom-made stream of your own choosing. The implementation will be irrelevant to the tasks accessing the protected object. It will also be irrelevant to the protected object itself. Jim Rogers Colorado Springs, Colorado USA