2

I wrote a low level audio player using CoreAudio in c# using xamarin.iOS.

In one of the classes, I have two volatile pointers in the following manner:

public unsafe volatile short* readPointer;
public unsafe volatile short* writePointer;

And the entire program compiles and works quite well.

I also set up a Jenkins build machine so it invokes mdtool on my project file to build it in AdHoc mode. However, when I build in this manner, I am getting the following error:

Build complete -- 2 errors, 0 warnings
MixerChannel.cs(21,39) : error CS0677: `MixerChannel.readPointer': A volatile field cannot be of the type `short*'
MixerChannel.cs(22,39) : error CS0677: `MixerChannel.writePointer': A volatile field cannot be of the type `short*'

According to MSDN, I am able to create volatile fields of the following types:

  • Any reference type
  • Any pointer type (in an unsafe context)
  • The types sbyte, byte, short, ushort, int, uint, char, float, bool
  • Enum types based on any of the above types

But this error seems to state otherwise.

The Jenkins build machine is exactly the same I use to build to debug. However, the build process is different: for debugging, I'm using the xamarin build host, and building from a Windows box with Visual Studio 2010. For the Jenkins build, I am using mdtool invoked remotely from the same Window box using plink.

Am I missing something obvious here? I strongly believe that compiler writers are demigods, and therefore any error is almost surely in my own code and not in the compiler.

Panda Pajama
  • 1,283
  • 2
  • 13
  • 31
  • Umm... why `volatile`? Are you sure you're using `volatile` correctly? Worst case scenario, hide the actual pointers behind properties that make explicit memory barriers - if that even makes sense on Xamarin.iOS. And, well, why pointers? You really want to hide those anyway. I understand that you're using it for interop, but that should be hidden far away, in a very simple (and safe) wrapper, not a `public unsafe volatile short*` :D – Luaan Apr 07 '15 at 12:13
  • @Luaan: This is code that runs in the Core Audio callback, which has real time thread priority, and an extremely tight deadline to finish. Apple explicitly recommends not to make any API calls, and especially those that may go into kernel mode to avoid audio glitches. I have a lockless producer-consumer system that works under the specific constraints of the Core Audio loop, which requires pointers to work. They need to be volatile for the system to work. – Panda Pajama Apr 07 '15 at 12:44

1 Answers1

2

Please refer to this https://bugzilla.xamarin.com/show_bug.cgi?id=23770 bug report and its status.

It appears that the compiler writers, although being demigods, can still make mistakes sometimes (in this case in the mono compiler).

Generally they either quickly correct those mistakes, or zap whoever mentions them with bolts of lightning.

But, you are in luck. This problem is supposed to be fixed in Mono 3.12. So check your version and upgrade.

Alex
  • 13,024
  • 33
  • 62
  • Hmm. I last updated xamarin about a month ago, so this fix should have been included. It is possible that it was only fixed for normal builds and not for `mdtool` builds. I'll check it tonight and see what happens. – Panda Pajama Apr 07 '15 at 03:29
  • I got the latest version and the error is solved. No need to report it. Thank you very much. – Panda Pajama Apr 13 '15 at 15:25
  • Well that saved you from their bolts of lightning. Lucky you. :D – Alex Apr 13 '15 at 15:26