Why does a std::atomic store with sequential consistency use XCHG?

mov-store + mfence and xchg are both valid ways to implement a sequential-consistency store on x86. The implicit lock prefix on an xchg with memory makes it a full memory barrier, like all atomic RMW operations on x86. (x86’s memory-ordering rules essentially make that full-barrier effect the only option for any atomic RMW: it’s both … Read more

using extern template (C++11) to avoid instantiation

You should only use extern template to force the compiler to not instantiate a template when you know that it will be instantiated somewhere else. It is used to reduce compile time and object file size. For example: // header.h template<typename T> void ReallyBigFunction() { // Body } // source1.cpp #include “header.h” void something1() { … Read more

What is std::move(), and when should it be used and does it actually move anything?

1. “What is it?” While std::move() is technically a function – I would say it isn’t really a function. It’s sort of a converter between ways the compiler considers an expression’s value. 2. “What does it do?” The first thing to note is that std::move() doesn’t actually move anything. It changes an expression from being … Read more

How to reset std::cin when using it?

You could use, when the condition, std::cin.fail() happens: std::cin.clear(); std::cin.ignore(); And then continue with the loop, with a continue; statement. std::cin.clear() clears the error flags, and sets new ones, and std::cin.ignore() effectively ignores them (by extracting and discarding them). Sources: cin.ignore() cin.clear()

MD5 hash from file in C++

Here’s a straight forward implementation of the md5sum command that computes and displays the MD5 of the file specified on the command-line. It needs to be linked against the OpenSSL library (gcc md5.c -o md5 -lssl) to work. It’s pure C, but you should be able to adapt it to your C++ application easily enough. … Read more

ASP.NET Core 1.0 on IIS error 502.5 – Error Code 0x80004005

I was able to fix it by running “C:\Program Files\dotnet\dotnet.exe” “C:\fullpath\PROJECT.dll” on the command prompt, which gave me a much more meaningful error: “The specified framework ‘Microsoft.NETCore.App’, version ‘1.0.1’ was not found. – Check application dependencies and target a framework version installed at: C:\Program Files\dotnet\shared\Microsoft.NETCore.App – The following versions are installed: 1.0.0 – Alternatively, install … Read more

What is the C# version of VB.NET’s InputBox?

Add a reference to Microsoft.VisualBasic, InputBox is in the Microsoft.VisualBasic.Interaction namespace: using Microsoft.VisualBasic; string input = Interaction.InputBox(“Prompt”, “Title”, “Default”, x_coordinate, y_coordinate); Only the first argument for prompt is mandatory

How do I initialize a const data member?

The const variable specifies whether a variable is modifiable or not. The constant value assigned will be used each time the variable is referenced. The value assigned cannot be modified during program execution. Bjarne Stroustrup’s explanation sums it up briefly: A class is typically declared in a header file and a header file is typically … Read more