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,3ccb707f4c91a5f2 X-Google-Attributes: gid103376,public From: geert@fozzie.sun3.iaf.nl (Geert Bosch) Subject: Fast locking (Was Re: Java vs Ada 95) Date: 1996/11/05 Message-ID: <55o4g4$ki8@fozzie.sun3.iaf.nl>#1/1 X-Deja-AN: 194767130 references: <325BC3B3.41C6@hso.link.com> <55gkch$gg6@fozzie.sun3.iaf.nl> organization: La Calandre Infortunee newsgroups: comp.lang.ada Date: 1996-11-05T00:00:00+00:00 List-Id: In article Robert Dewar writes: Geert said "In the more general case a very simple spin-lock is enough and the overhead should only be one memory-read when the object is not locked. String objects are locked almost never and when they are locked they are only locked for a short time." What do you mean by a very simple spin lock in a uniprocessor environment. I meant a lock that uses some form of busy-waiting instead of blocking. Such a lock can be implemented using atomic test-and-set or atomic swap. Although these locks are not efficient for long waits because of wasted CPU time and possible starving of other tasks, for resources that are only locked for a short time, like the ref-counted bounded string example, they are the best solution. When implementing a sample package for spin locks I found that GNAT doesn't provide intrinsic subprograms as described in Annex C of the RM: "It is recommended that intrinsic subprograms be provided for convenient access to any machine operations that provide special capabilities or efficiency that are not otherwise available through the language constructs." (RM95 C.1(11)) This means that test-and-set is not possible using just GNAT at the moment and indeed implementing efficient spin-locks is not possible. Hopefully the extra intrinsic subprograms will be implemented sometime. Regards, Geert -- E-Mail: geert@sun3.iaf.nl