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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no 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!news.eternal-september.org!feeder.eternal-september.org!news.glorb.com!peer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post02.iad.highwinds-media.com!fx14.iad.POSTED!not-for-mail From: Shark8 User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:32.0) Gecko/20100101 Thunderbird/32.0a1 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Safety of unprotected concurrent operations on constant objects References: <7403d130-8b42-43cd-a0f1-53ba34b46141@googlegroups.com> In-Reply-To: Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Message-ID: X-Complaints-To: abuse@teranews.com NNTP-Posting-Date: Sun, 04 May 2014 20:25:27 UTC Organization: TeraNews.com Date: Sun, 04 May 2014 14:25:26 -0600 X-Received-Bytes: 2577 X-Received-Body-CRC: 2331583590 Xref: news.eternal-september.org comp.lang.ada:19669 Date: 2014-05-04T14:25:26-06:00 List-Id: On 04-May-14 01:46, Natasha Kerensikova wrote: > I have some shared resources indexed by a string, described in a > file, and considered as constant throughout the lifetime of the program > (with the standard scheme "restart for changes to take effect"). What's the problem, then, with making the entire map constant? Some_Map : Constant Ordered_Map:= Load_From_File; Or, I suppose, something like wrapping it in a protected object? (Then you have its accesses blocked off.) ---------- As a matter of last resort you could use a package: Package Data_Map is Function Get( Index: String ) return Data_Type; No_Index : Exception; End Data_Map; Package Body Data_Map is Type Item_List is Array(Positive Range <>) of Unbounded_String; Function Load_From_File return Item_List is -- ... Implementation : constant Item_List:= Load_From_File; -- Naive linear-search; could be optimized, provided Load_From_File -- returns its list as a sorted list... for small data-sets this -- should suffice. Function Index_Of( Item : String ) Return Positive is begin For Index in Implementation'Range loop if Implementation(Index) = To_Unbounded_String(Item) then Return Index; end if; end loop; Raise No_Index; end Index_Of; Function Get( Index: String ) return Data_Type is Item_Number : Positive renames Index_Of(Index); begin Return Result : constant Data_Type := Implementation( Item_Number ); end Get; End Data_Map;