volatile in java with long, int, boolean, and many different cases of write
a. your answer is fine (i.e. volatile is not enough)
b. "it is NEVER an atomic operation because long takes two write cycles for the upper and lower 32 bit writes and reads" => that is too strong for non volatile variables: non volatile long assignment may or may not be atomic. It is generally atomic on 64-bit processors but the Java Memory Model does not give any guarantees. However volatile long assignment is guaranteed to be atomic.
c. your answer is fine (although I don't understand what you mean by "before an interrupt occurs")
d. your answer is fine
How does C handle non-booleans in an if statement?
your guess is right:
from §6.8.4.1 of WG14/N1256
the first substatement is executed if the expression compares unequal to 0
Why I getting an Expression always true warning?
If your code enters the first else block it means that (varKnownFolder == null)
was evaluated to false.
So the second check is useless as varKnownFolder
could never be null in this block.
public async Task<Metadata> GetFolderAsync(string strDirectoryPathName, dynamic varKnownFolder = null)
{
using (await _FolderPathToInfoMapSync.EnterAsync().ConfigureAwait(false))
{
Metadata objFolder;
string strPathName = strDirectoryPathName;
if (varKnownFolder == null)
{
// This would happen if varKnownFolder is null
objFolder = await _Storage.Client.Files.GetMetadataAsync(strPathName);
}
else
{
// The code enters HERE BECAUSE varKnownFolder is not null
if (varKnownFolder != null) // <-- So this check is useless
_FolderPathToInfoMap.Add(strDirectoryPathName, varKnownFolder);
else
objFolder = null;
}
return objFolder;
}
}
Also, it means that you could replace it with this :
public async Task<Metadata> GetFolderAsync(string strDirectoryPathName, dynamic varKnownFolder = null)
{
using (await _FolderPathToInfoMapSync.EnterAsync().ConfigureAwait(false))
{
Metadata objFolder = null;
string strPathName = strDirectoryPathName;
if (varKnownFolder == null)
{
objFolder = await _Storage.Client.Files.GetMetadataAsync(strPathName);
}
else
{
// The code enters HERE BECAUSE varKnownFolder is not null
_FolderPathToInfoMap.Add(strDirectoryPathName, varKnownFolder);
}
return objFolder;
}
}
Related Topics
Embedding Resources in Executable Using Gcc
Forward Declaration of Nested Types/Classes in C++
Why Doesn't a Simple "Hello World"-Style Program Compile With Turbo C++
Pure Virtual Destructor in C++
C++: Life Span of Temporary Arguments
Compilers and Argument Order of Evaluation in C++
How to Properly Delete Nodes of Linked List in C++
How to Have Functions Inside Functions in C++
Return Type of ':' (Ternary Conditional Operator)
Is "Argv[0] = Name-Of-Executable" an Accepted Standard or Just a Common Convention
How to Get Main Window Handle from Process Id
How to Get and Use the Header File ≪Graphics.H≫ in My C++ Program
C++ Standard Library: How to Write Wrappers For Cout, Cerr, Cin and Endl