29-Nov-2020 01:42 GMT.
[Forum] OS4 design for ObtainSysList/ReleaseSysListANN.lu
Posted on 11-Jul-2004 20:44 GMT by adesigner (Edited on 2004-07-12 02:34:47 GMT by Christophe Decanini)114 comments
View flat
View list
"In the documentation of FindPort() it is said that you should use ObtainSysList(OSL_PORTLIST) and ReleaseSysList() instead of Forbit() and Permit() in OS4."
www.amigaworld.net thread

I believe this is broken design, you can't mix Forbid and semaphore locking. (Edit by Christophe: It has been confirmed that this solution was rejected for OS4) [sort of pseudo code follows]

" static struct MsgPort *Port;

int InitThePort(void)
struct MsgPort *newport;
int result = 0;

ObtainSysList(OSL_PORTLIST); /* Forbid(); */
Port = FindPort(MYPORTNAME);
if (Port) {
result = 2;
} else {
newport = AllocMem(sizeof(*newport), MEMF_PUBLIC);
if (newport) {
/* ... init newport ... */
Port = newport;
result = 1;
} else result = 0;
} else result = 0;

ReleaseSysList(OSL_PORTLIST); /* Permit(); */
return result;

The problem here is that if some other app is using Forbid() locking, it can easily end up AddPort()ng duplicate port with the same name.

This can happen if task A using ObtainSysList reaches just before AddPort, and Task B using Forbid gets scheduled to run. This task will then Forbid, FindPort and get NULL too. Task B (that is run within Forbid) will now continue and create new port and add it to system via AddPort.

Next Task B Permits and lets other tasks run. Now Task A gets to run and continues to AddPort *duplicate* port.

Further problems may arise if application FindPorting for this port is using Forbid. There the port is actually found *before* InitThePort reaches ReleaseSysList. Now if some further initializing of resources is done before this call, messages might get lost in case these initializations fail, and the app assumes no messages can be in the port (the port list is locked after all, so there should't be any, right?).

RemPort has similar issues, but there the problem is that FindPort can find the port even after ObtainSysList is called for RemPort, and thus more messages might appear in the port even after this ObtainSysList.

Note that AddPort/FindPort itself must not break Forbid. There are a lot more ways that things can break down, I just listed some. Also here I only considered public port list, other system lists have even greater problems.

I ask developers to review these findings and if I am wrong, correct me.

List of all comments to this article
Sorted by date, most recent at bottom
Comment 1Fabio AlemagnaRegistered user11-Jul-2004 19:08 GMT
Comment 2Anonymous11-Jul-2004 19:17 GMT
Comment 3Richi11-Jul-2004 19:17 GMT
Comment 4Fabio AlemagnaRegistered user11-Jul-2004 19:25 GMT
Comment 5Amon_ReRegistered user11-Jul-2004 19:34 GMT
Comment 6Fabio AlemagnaRegistered user11-Jul-2004 19:44 GMT
Comment 7Anonymous11-Jul-2004 19:46 GMT
Comment 8Amon_ReRegistered user11-Jul-2004 19:52 GMT
Comment 9Fabio AlemagnaRegistered user11-Jul-2004 19:55 GMT
Comment 10Fabio AlemagnaRegistered user11-Jul-2004 19:56 GMT
Comment 11Amon_ReRegistered user11-Jul-2004 19:57 GMT
Comment 12Kolbjørn Barmen11-Jul-2004 20:11 GMT
Comment 13Fabio AlemagnaRegistered user11-Jul-2004 20:23 GMT
Comment 14Peter Gordon11-Jul-2004 20:38 GMT
Comment 15Johan Rönnblom11-Jul-2004 20:46 GMT
Comment 16Anonymous11-Jul-2004 20:54 GMT
Comment 17Fabio AlemagnaRegistered user11-Jul-2004 20:55 GMT
Comment 18Fabio AlemagnaRegistered user11-Jul-2004 21:00 GMT
Comment 19Peter Gordon11-Jul-2004 21:00 GMT
Comment 20Thomas FriedenRegistered user11-Jul-2004 21:02 GMT
Comment 21Thomas FriedenRegistered user11-Jul-2004 21:04 GMT
Comment 22Fabio AlemagnaRegistered user11-Jul-2004 21:04 GMT
Comment 23Peter Gordon11-Jul-2004 21:04 GMT
Comment 24Fabio AlemagnaRegistered user11-Jul-2004 21:11 GMT
Comment 25Johan Rönnblom11-Jul-2004 21:12 GMT
Comment 26Peter Gordon11-Jul-2004 21:24 GMT
Comment 27adesigner11-Jul-2004 21:25 GMT
Comment 28Peter Gordon11-Jul-2004 21:34 GMT
Comment 29Fabio AlemagnaRegistered user11-Jul-2004 21:36 GMT
Comment 30adesigner11-Jul-2004 21:39 GMT
Comment 31Peter Gordon11-Jul-2004 21:43 GMT
Comment 32Peter Gordon11-Jul-2004 21:44 GMT
Comment 33Peter Gordon11-Jul-2004 21:47 GMT
Comment 34adesigner11-Jul-2004 21:51 GMT
Comment 35Peter Gordon11-Jul-2004 21:57 GMT
Comment 36adesigner11-Jul-2004 22:03 GMT
Comment 37Peter Gordon11-Jul-2004 22:05 GMT
Comment 38Peter Gordon11-Jul-2004 22:05 GMT
Comment 39Peter Gordon11-Jul-2004 22:09 GMT
Comment 40adesigner11-Jul-2004 22:31 GMT
Comment 41itix11-Jul-2004 23:00 GMT
Comment 42Stefan Burström11-Jul-2004 23:07 GMT
Comment 43Amon_ReRegistered user12-Jul-2004 03:34 GMT
Comment 44Peter Gordon12-Jul-2004 06:15 GMT
Comment 45Georg Steger12-Jul-2004 07:41 GMT
Comment 46Peter Gordon12-Jul-2004 08:12 GMT
Comment 47Fabio AlemagnaRegistered user12-Jul-2004 08:27 GMT
Comment 48Peter Gordon12-Jul-2004 08:56 GMT
Comment 49DET Nicolas12-Jul-2004 09:19 GMT
Comment 50DET Nicolas12-Jul-2004 09:19 GMT
Comment 51Fabio AlemagnaRegistered user12-Jul-2004 09:28 GMT
Comment 52Georg Steger12-Jul-2004 09:38 GMT
Comment 53Fabio AlemagnaRegistered user12-Jul-2004 10:13 GMT
Comment 54Peter Gordon12-Jul-2004 10:54 GMT
Comment 55Christophe DecaniniRegistered user12-Jul-2004 12:52 GMT
Comment 56Johan Rönnblom12-Jul-2004 13:36 GMT
Comment 57Anonymous12-Jul-2004 16:04 GMT
Comment 58NekoRegistered user12-Jul-2004 17:29 GMT
Comment 59Thomas FriedenRegistered user13-Jul-2004 08:03 GMT
Comment 60Thomas FriedenRegistered user13-Jul-2004 08:06 GMT
Comment 61Thomas FriedenRegistered user13-Jul-2004 08:11 GMT
Comment 62Thomas FriedenRegistered user13-Jul-2004 08:15 GMT
Comment 63Thomas FriedenRegistered user13-Jul-2004 08:18 GMT
Comment 64Anonymous13-Jul-2004 09:06 GMT
Comment 65Fabio AlemagnaRegistered user13-Jul-2004 09:54 GMT
Comment 66Fabio AlemagnaRegistered user13-Jul-2004 09:58 GMT
Comment 67Fabio AlemagnaRegistered user13-Jul-2004 10:08 GMT
Comment 68Fabio AlemagnaRegistered user13-Jul-2004 10:16 GMT
Comment 69Peter Gordon13-Jul-2004 10:39 GMT
Comment 70Johan Rönnblom13-Jul-2004 13:51 GMT
Comment 71MIKE13-Jul-2004 14:32 GMT
Comment 72Johan Rönnblom13-Jul-2004 19:28 GMT
Comment 73Thomas FriedenRegistered user14-Jul-2004 07:09 GMT
Comment 74Thomas FriedenRegistered user14-Jul-2004 07:11 GMT
Comment 75Thomas FriedenRegistered user14-Jul-2004 07:15 GMT
Comment 76Thomas FriedenRegistered user14-Jul-2004 07:18 GMT
Comment 77Fabio AlemagnaRegistered user14-Jul-2004 08:32 GMT
Comment 78Fabio AlemagnaRegistered user14-Jul-2004 08:33 GMT
Comment 79priest14-Jul-2004 10:01 GMT
Comment 80Fabio AlemagnaRegistered user14-Jul-2004 10:31 GMT
Comment 81Fabio AlemagnaRegistered user14-Jul-2004 10:35 GMT
Comment 82pixie14-Jul-2004 18:22 GMT
Comment 83Ketzer16-Jul-2004 07:35 GMT
Comment 84Ketzer16-Jul-2004 07:38 GMT
Comment 85Ketzer16-Jul-2004 07:42 GMT
Comment 86Ketzer16-Jul-2004 07:44 GMT
Comment 87Ketzer16-Jul-2004 08:37 GMT
Comment 88Fabio AlemagnaRegistered user16-Jul-2004 08:50 GMT
Comment 89Fabio AlemagnaRegistered user16-Jul-2004 08:51 GMT
Comment 90Fabio AlemagnaRegistered user16-Jul-2004 08:52 GMT
Comment 91Fabio AlemagnaRegistered user16-Jul-2004 08:53 GMT
Comment 92Fabio AlemagnaRegistered user16-Jul-2004 08:58 GMT
Comment 93Ketzer16-Jul-2004 09:13 GMT
Comment 94Ketzer16-Jul-2004 09:19 GMT
Comment 95Ketzer16-Jul-2004 09:34 GMT
Comment 96Ketzer16-Jul-2004 09:44 GMT
Comment 97Fabio AlemagnaRegistered user16-Jul-2004 10:15 GMT
Comment 98Fabio AlemagnaRegistered user16-Jul-2004 10:30 GMT
Comment 99Fabio AlemagnaRegistered user16-Jul-2004 10:30 GMT
Comment 100Ketzer16-Jul-2004 10:39 GMT
Comment 101Ketzer16-Jul-2004 10:43 GMT
Comment 102Fabio AlemagnaRegistered user16-Jul-2004 10:49 GMT
Comment 103Ketzer16-Jul-2004 11:00 GMT
Comment 104Ketzer16-Jul-2004 11:11 GMT
Comment 105Fabio AlemagnaRegistered user16-Jul-2004 11:18 GMT
Comment 106Fabio AlemagnaRegistered user16-Jul-2004 11:21 GMT
Comment 107Ketzer16-Jul-2004 11:33 GMT
Comment 108Ketzer16-Jul-2004 11:38 GMT
Comment 109Fabio AlemagnaRegistered user16-Jul-2004 11:56 GMT
Comment 110Alkis TsapanidisRegistered user16-Jul-2004 12:04 GMT
Comment 111Alkis TsapanidisRegistered user16-Jul-2004 12:08 GMT
Comment 112Ketzer16-Jul-2004 12:16 GMT
Comment 113Ketzer16-Jul-2004 12:27 GMT
Comment 114Ketzer16-Jul-2004 12:42 GMT
Back to Top