Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VS2013 atomic_flag compile error #3

Closed
Ron2 opened this issue Nov 12, 2014 · 4 comments
Closed

VS2013 atomic_flag compile error #3

Ron2 opened this issue Nov 12, 2014 · 4 comments

Comments

@Ron2
Copy link

Ron2 commented Nov 12, 2014

Hi, thanks for making this project. I've been doing C# for over seven years, so it's a good learning experience for me!

When trying to get this running in Visual Studio 2013, I got this compile error:

Error   1   error C2280: 'std::atomic_flag::atomic_flag(const std::atomic_flag &)' : attempting to reference a deleted function c:\sceadev\github\concurentqueue\concurrentqueue\concurrentqueue.h  438 1   LockFreeConcurrentQueue

The compile error is because this member initializer:

        implicitProducerHashResizeInProgress(ATOMIC_FLAG_INIT),

... uses a constructor that is deleted:

    atomic_flag(const atomic_flag&) = delete;

The default parameterless constructor is available, so the fix is to remove the ATOMIC_FLAG_INIT parameter and the atomic_flag still gets initialized to zero. Line 436 becomes:

        implicitProducerHashResizeInProgress(),

I have no idea what the repercussions are for other compilers. I also don't understand why you haven't encountered this problem. I'm compiling for Win32, in case that matters.

--Ron

@cameron314
Copy link
Owner

Thanks for opening an issue!

I haven't encountered it because I haven't gotten around to adding VS2013 support yet (expect a solution + projects for the tests and benchmarks soonish).

Apparently it's unspecified in the C++11 standard whether ATOMIC_FLAG_INIT can be used in other ways than atomic_flag_t foo = ATOMIC_FLAG_INIT. It seems GCC accepts it as a constructor argument and VS does not.

What is specified is that calling the default constructor does not necessarily initialize the object to the cleared state (which is silly, in my opinion). So the fix is to leave it uninitialized and then assign to it in the constructor of the queue, which should be portable across all compilers.

@cameron314
Copy link
Owner

Done. Let me know if you run into any other issues!

@cameron314
Copy link
Owner

Wow, I shouldn't fix bugs on my way to bed. That first commit didn't compile, as I changed it to call the assignment operator (ATOMIC_FLAG_INIT only works on initialization with =). The correct way to do it is to leave it initialized to its indeterminate starting state, then call clear().

@Ron2
Copy link
Author

Ron2 commented Nov 12, 2014

It looks good to me! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants