我研究了Java内存模型并看到了重新排序问题.一个简单的例子:
boolean first = false;
boolean second = false;
void setValues() {
first = true;
second = true;
}
void checkValues() {
while(!second);
assert first;
}
Run Code Online (Sandbox Code Playgroud)
重新排序是非常不可预测和奇怪的.此外,它破坏了抽象.我认为处理器架构必须有充分的理由去做一些对程序员来说太不方便的事情. 这些原因是什么?
有很多关于如何处理重新排序的信息,但我找不到任何关于它为什么需要的信息.在任何地方,人们只会说"这是因为一些性能优势".例如,second之前存储的性能优势是first什么?
您能推荐一些关于此的文章,论文或书籍,或者自己解释一下吗?
java optimization multithreading cpu-architecture compiler-optimization
我刚开始使用“使用Haskell编程”一书来学习haskell。我要尝试做的第一个想法就是简单地从本书中编译世界示例。我在hello.hc文件中的代码是:
main = do
printStrLn "Hello!"
Run Code Online (Sandbox Code Playgroud)
我使用命令运行ghc
ghc hello.hc
Run Code Online (Sandbox Code Playgroud)
但是我得到的只是一个错误!
hello.hc:1:1: error:
warning: data definition has no type or storage class
main = do
^
hello.hc:1:1: error:
warning: type defaults to 'int' in declaration of 'main' [-Wimplicit-int]
hello.hc:1:8: error:
error: expected expression before 'do'
main = do
^
`gcc.exe' failed in phase `C Compiler'. (Exit code: 1)
Run Code Online (Sandbox Code Playgroud)
我的Haskell平台版本为8.01,