[foreign-jextract] RFR: Minor change for possible race in shared resource list

Maurizio Cimadamore mcimadamore at openjdk.java.net
Sat Apr 24 10:44:43 UTC 2021


On Sat, 24 Apr 2021 01:40:40 GMT, Radoslaw Smogura <github.com+7535718+rsmogura at openjdk.org> wrote:

> (1) One or more threads can see "prev" as CLOSED_LIST. Even those CAS will be performed
> and list head will be set to new cleanup. Than exception is going to be thrown.
> 
> (2) Than cleanup will continue (maybe skipping just added cleanup).
> 
> If in addition, other thread will join in parallel to (1) with cleanup2, than
> queue could look like this HEAD = cleanup2 -> list end marker.

I'm not sure there's a problem. Yes, we set "next" on the provided resource cleanup object - and if we throw an exception, this value will be CLOSED_LIST. However, in the code logic, it seems to me that we are always creating a "new" ResourceCleanup before adding it to the ResourceList - so if adding throws, the resource has not been added, so this cannot cause issues when cleaning up the resource scope.

The only way I can see this being a problem is the "same" ResourceScope instance is repeatedly added to a resource scope, possibly from multiple threads - in which case there might be a race in setting the next field - but this is not how the API implementation operates internally. Is there a test which demonstrates the issues, e.g. where wrong behavior might occur? Note that even the new patch races to set the next field to NULL... it seems to me that correctness of this code is enforced holistically, by looking at the places where the code is used.

-------------

PR: https://git.openjdk.java.net/panama-foreign/pull/519


More information about the panama-dev mailing list