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 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: A Simpler Find Tool Date: Sun, 21 May 2017 07:49:31 +0100 Organization: A noiseless patient Spider Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="0e89d1fdb0b563b1584c697fd31ef5ad"; logging-data="27987"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+DMQlo0oUHdR85RZ912PLR+54egRWBnRE=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (darwin) Cancel-Lock: sha1:ozRBRKKvjDD/k3CWMkL+Swbo4ZU= sha1:Bfu84VikNk3TqUBh2yp7CONcba0= Xref: news.eternal-september.org comp.lang.ada:46831 Date: 2017-05-21T07:49:31+01:00 List-Id: Brian Kolden writes: > I made a simple find tool for Linux, https://github.com/bkold/finda, > and I was wondering if I could optimize the task scheduling a bit. > > protected body Task_Pool_Status is > procedure Check (Thread_Pointer : out Thread_Access) is > begin > for I in Status'Range loop > if Status(I) = Ready then > Status(I) := Working; > Thread_Pointer := Threads(I); > return; > end if; > end loop; > Thread_Pointer := Null; > end Check; > > procedure End_Thread (Thread_Num : in CPU) is > begin > Status(Thread_Num) := Ready; > end End_Thread; > end Task_Pool_Status; > > I'm using a request and reserve model to determine which threads are > waiting and which are busy. The threads call End_Thread when they > finish their work in order to be available to be queued again. I think > the model itself is good, but I was unhappy with how I find the > sleeping threads. Does anyone have a cleaner suggestion? Just how many threads are you expecting to have? Is it worth saving some cycles here? You could have a queue of Ready threads, pop a thread when required, push when done. That would allow you to have an entry, which would save the polling? entry Get (A_Thread : out Thread_Access) when Queue.Head /= null is