Click Here
home features news forums classifieds faqs links search
6043 members 
Amiga Q&A /  Free for All /  Emulation /  Gaming / (Latest Posts)
Login

Nickname

Password

Lost Password?

Don't have an account yet?
Register now!

Support Amigaworld.net
Your support is needed and is appreciated as Amigaworld.net is primarily dependent upon the support of its users.
Donate

Menu
Main sections
» Home
» Features
» News
» Forums
» Classifieds
» Links
» Downloads
Extras
» OS4 Zone
» IRC Network
» AmigaWorld Radio
» Newsfeed
» Top Members
» Amiga Dealers
Information
» About Us
» FAQs
» Advertise
» Polls
» Terms of Service
» Search

IRC Channel
Server: irc.amigaworld.net
Ports: 1024,5555, 6665-6669
SSL port: 6697
Channel: #Amigaworld
Channel Policy and Guidelines

Who's Online
10 crawler(s) on-line.
 13 guest(s) on-line.
 0 member(s) on-line.



You are an anonymous user.
Register Now!
 Seiya:  7 mins ago
 NutsAboutAmiga:  15 mins ago
 spudmiga:  25 mins ago
 Karlos:  41 mins ago
 XyPsy:  43 mins ago
 Rob:  56 mins ago
 DiscreetFX:  1 hr 30 mins ago
 clint:  1 hr 49 mins ago
 bennymee:  1 hr 51 mins ago
 QBit:  2 hrs 9 mins ago

/  Forum Index
   /  Amiga Inc. offshoot
      /  Race condition shortcut
Register To Post

PosterThread
gonegahgah 
Race condition shortcut
Posted on 6-Dec-2022 8:22:18
#1 ]
Regular Member
Joined: 5-Dec-2008
Posts: 144
From: Australia

I came across an interesting thing yesterday where waiting was avoided in some instances without creating a race condition. I didn't understand the process initially but now it makes sense.

Once upon a time, back in history, the TAO OS was touted as the way forward for Amiga.
Sadly, alack, there were a lot of things in Tao that would have made this very difficult to achieve.
Despite that, it does have a lot of interesting things within it.
For example, whereas Amiga has libraries, Tao simply has tools.

Now, the situation that revealed this 'waiting shortcut' was its static data implementation.
Static data allows a tool (which as mentioned is similar to an Amiga library) to retain a value between calls for a particular execution. So you can call the tool multiple times and the static data will not be forgotten by that tool between calls.

That static data has to basically be tied to a process and that tool.
It is tied to a process by checking if the global pointer equals the current check value.
If it does equal then you already have the static data and don't need to do any more.
If it doesn't then you have to go looking for the static data (whereby it is found or initially created).

Here is example code:

cpy [pCache.sc_Data], pStatics ; Get the statics data hopefuly
if [pCache.sc_Check] != gp ; Check if it belongs to our process?
qcall sys/kn/statics/statics_get,(pCache,[pControl.sc_Tool],pControl,pUserData: pStatics,iError) ; If it doesn't, go find it.
endif

There is no visible waiting in the first two lines when we get the static data.
It is certain that there is a wait in the 3rd line tool because it will be dealing with a shared list.

I wasn't aware CPUs have atomic operations meaning they don't get interrupted until they complete.
That was the answer to the puzzle for me.

Basically we want the statics when we enter this code but we don't want to slow down if we already have them; only if we don't have them. So we grab the statics data pointer. We then check if the last one to update the statics pointer was our process. If it was then no more to do as our statics pointer is correct. Otherwise it may not be and we go find it using the shared list under lock.

This works because the statics pointer won’t change while we are getting it and even though sc_check might change after we get the statics pointer, the only process that will change it to our gp will be our process during a lock. So if it still equals gp then no other process has changed the gp value meaning the statics pointer had not been changed at that point.

I hope that makes sense? Maybe someone else can explain it better than me…
That’s if anyone reads this post seeing it won’t go on the main page!
Anyhow, hope that is of interest to someone else as well.

I was curious if that happens in any other code that anyone might know of?

Last edited by gonegahgah on 06-Dec-2022 at 08:23 AM.
Last edited by gonegahgah on 06-Dec-2022 at 08:23 AM.

 Status: Offline
Profile     Report this post  

[ home ][ about us ][ privacy ] [ forums ][ classifieds ] [ links ][ news archive ] [ link to us ][ user account ]
Copyright (C) 2000 - 2019 Amigaworld.net.
Amigaworld.net was originally founded by David Doyle