Bug 42413 - Volatile fields don't enforce acquire - release semantics like Volatile.Read() and Volatile.Write()
Summary: Volatile fields don't enforce acquire - release semantics like Volatile.Read(...
Status: RESOLVED FIXED
Alias: None
Product: Runtime
Classification: Mono
Component: JIT (show other bugs)
Version: 4.4.0 (C7)
Hardware: All All
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-07-07 22:39 UTC by Petros Douvantzis
Modified: 2016-07-08 07:40 UTC (History)
4 users (show)

See Also:
Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
2 test scripts that reproduce the error in iOS and Android (4.87 KB, application/x-zip-compressed)
2016-07-07 22:39 UTC, Petros Douvantzis
Details

Description Petros Douvantzis 2016-07-07 22:39:44 UTC
Created attachment 16607 [details]
2 test scripts that reproduce the error in iOS and Android

According to C# specification: 

•	A read of a volatile field is called a volatile read. A volatile read has “acquire semantics”; that is, it is guaranteed to occur prior to any references to memory that occur after it in the instruction sequence. 
•	A write of a volatile field is called a volatile write. A volatile write has “release semantics”; that is, it is guaranteed to happen after any memory references prior to the write instruction in the instruction sequence.

It seems that Mono 4.4 (the one used in Xamarin) does not enforce these semantics or in other words does not prevent memory re-ordering in Android and iOS that have relaxed memory models due to their CPU.  

I am attaching a zip that contains 2 tests that reproduce the problem in iOS and Android. I have added more details in the readme file.

The issue has been discussed in the dev list: http://mono.1490590.n4.nabble.com/Volatile-fields-don-t-enforce-acquire-release-semantics-like-Volatile-Read-and-Volatile-Write-td4668111.html
Comment 1 Zoltan Varga 2016-07-08 00:15:24 UTC
Fixed in mono master/4.6.0 branch. Thanks for the testcase.
Comment 2 Petros Douvantzis 2016-07-08 07:40:04 UTC
That was fast!
Thank you!

Notice (2018-05-21): bugzilla.xamarin.com will be switching to read-only mode on Thursday, 2018-05-25 22:00 UTC.

Please join us on Visual Studio Developer Community and GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs and copy them to the new locations as needed for follow-up. The See Also field on each Bugzilla bug will be updated with a link to its new location when applicable.

After Bugzilla is read-only, if you have new information to add for a bug that does not yet have a matching issue on Developer Community or GitHub, you can create a follow-up issue in the new location. Copy and paste the title and description from this bug, and then add your new details. You can get a pre-formatted version of the title and description here:

In special cases you might also want the comments:

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Note You need to log in before you can comment on or make changes to this bug.