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.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 2002:ac8:7445:: with SMTP id h5mr39401926qtr.101.1571149890865; Tue, 15 Oct 2019 07:31:30 -0700 (PDT) X-Received: by 2002:a9d:7356:: with SMTP id l22mr1094852otk.16.1571149890607; Tue, 15 Oct 2019 07:31:30 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!news.gegeweb.eu!gegeweb.org!usenet-fr.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!o24no10568099qtl.0!news-out.google.com!q23ni857qtl.1!nntp.google.com!o24no10568093qtl.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Tue, 15 Oct 2019 07:31:30 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=47.185.223.245; posting-account=zwxLlwoAAAChLBU7oraRzNDnqQYkYbpo NNTP-Posting-Host: 47.185.223.245 References: <5da4cf81$0$20312$426a74cc@news.free.fr> <5da4e182$0$20321$426a74cc@news.free.fr> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: How to transfer Class-Wide object to a Task ? From: Optikos Injection-Date: Tue, 15 Oct 2019 14:31:30 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Xref: reader01.eternal-september.org comp.lang.ada:57292 Date: 2019-10-15T07:31:30-07:00 List-Id: On Tuesday, October 15, 2019 at 2:21:51 AM UTC-5, Dmitry A. Kazakov wrote: > On 2019-10-14 22:58, William FRANCK wrote: >=20 > > Here is the multitasking part (simplified) (working, no issue) > > for reading the datafile, and writing it back (after some data-process) > >=20 > > My first intention was : while Writing.Bloc is busy writing on the=20 > > output file, Reading.Bloc can take 1 record in advance >=20 > That is what OS asynchronous I/O does already. But that is aside. >=20 > > Now I have to insert the class-wide object passing in the Bloc. >=20 > Stream attributes 'Input and 'Output would do. >=20 > > As You mentionned, should I use a protected type (FIFO)=C2=A0 instead o= f 2 //=20 > > tasks ? >=20 > A protected object to synchronize two tasks: >=20 > Producer -> FIFO -> Consumer > Block put <- PO -> Block get > when full when empty >=20 > FIFO does not need interlocking in this scenario. Protected object is=20 > only to prevent busy waiting at the ends. >=20 > Since you are working with streams you can use a storage stream instead= =20 > of raw FIFO: >=20 > Producer -> Storage stream -> Consumer > Block write when full Block read when empty >=20 > I still do not understand why you serialize and deserialize insted of=20 > copying bytes as they are. Because OPer is apparently migrating code that was in 2 (UNIXesque) process= es to instead be 2 threads in the same process. William Franck, you really should rework your design to do as Dmitry advise= s: FIFO message queues between 2 otherwise asynchronous threads that work = on their own slice of the problem (and have their own slice of the problem'= s data structures). Under that revised design, only the FIFO's internals n= eed to worry about thread safety, because before posting and after retrievi= ng from the queue the 2 threads run full tilt in their independent territor= y without interacting with each other. (This of course assumes that there = exists some sort of slicing/partitioning of your problem-space, but there u= sually is if you look intensely enough for well-defined demarcations.)