我是Haskell的新手.总是让我感到困惑的一件事是,Haskell是否是一个托管(从MS借用的术语)语言(如Java)或编译到本机代码(如C)的模糊性?
GHC页面说明"GHC将Haskell代码直接编译为本机代码或使用LLVM作为后端".
在"编译为本机代码"的情况下,如果没有像JVM这样的东西,垃圾收集等功能是如何实现的?
/ 更新 /
非常感谢您的回答.从概念上讲,您可以帮助指出我对Haskell中垃圾收集的以下哪些理解是正确的:
GHC将Haskell代码编译为本机代码.在编译处理中,垃圾收集例程会被添加到原始程序代码中吗?
要么
有一个程序与Haskell程序一起运行以执行垃圾收集?
由于某些错误,我需要对下面代码的意外结果进行一些解释.
reverse' :: [b] -> [b]
reverse' [] = []
reverse' [x] = [x]
reverse'(x:xs) = last (x:xs) : reverse' xs
*Main> reverse' [0,8,2,5,6,1,20,99,91,1]
[1,1,1,1,1,1,1,1,1,1]
Run Code Online (Sandbox Code Playgroud)
这是因为一些错误吗?
根据文档,AtomicInteger.incrementAndGet()是原子的.但是,在下面的源代码中,如果另一个线程在"返回下一个"之前交错怎么办?那么"下一步"会不正确吗?
public final long incrementAndGet() {
for (;;) {
long current = get();
long next = current + 1;
if (compareAndSet(current, next))
return next;
}
}
Run Code Online (Sandbox Code Playgroud) 我遇到了这个并发问题,我已经挠头好几天了。
基本上,我希望我的 ThreadPoolExecutor 在关闭之前等待所有任务(任务数量未知)完成。
public class AutoShutdownThreadPoolExecutor extends ThreadPoolExecutor{
private static final Logger logger = Logger.getLogger(AutoShutdownThreadPoolExecutor.class);
private int executing = 0;
private ReentrantLock lock = new ReentrantLock();
private final Condition newTaskCondition = lock.newCondition();
private final int WAIT_FOR_NEW_TASK = 120000;
public AutoShutdownThreadPoolExecutor(int coorPoolSize, int maxPoolSize, long keepAliveTime,
TimeUnit seconds, BlockingQueue<Runnable> queue) {
super(coorPoolSize, maxPoolSize, keepAliveTime, seconds, queue);
}
@Override
public void execute(Runnable command) {
lock.lock();
executing++;
lock.unlock();
super.execute(command);
}
@Override
protected void afterExecute(Runnable r, Throwable t) {
super.afterExecute(r, t);
try{
lock.lock(); …Run Code Online (Sandbox Code Playgroud) 谁能让我知道这段代码出了什么问题?我把头发拉出来!
如果我使用HashMap而不是ConcurrentHashMap没有任何问题.代码使用JDK 5.0编译
public class MapTest {
public Map<DummyKey, DummyValue> testMap = new ConcurrentHashMap<DummyKey, DummyValue>();
public MapTest() {
DummyKey k1 = new DummyKey("A");
DummyValue v1 = new DummyValue("1");
DummyKey k2 = new DummyKey("B");
DummyValue v2 = new DummyValue("2");
testMap.put(k1, v1);
testMap.put(k2, v2);
}
public void printMap() {
for(DummyKey key : testMap.keySet()){
System.out.println(key.getKeyName());
DummyValue val = testMap.get(key);
System.out.println(val.getValue());
}
}
public static void main(String[] args){
MapTest main = new MapTest();
main.printMap();
}
private static class DummyKey {
private String keyName = …Run Code Online (Sandbox Code Playgroud) 我想使用 sed 在模式之前插入一行: - Insert 'XmlRootElement(name="ABC")' before "public class"
这是脚本:
'/public class/i\@XmlRootElement(name="ABC")'
Run Code Online (Sandbox Code Playgroud)
但是,当我运行此命令时出现错误:
sed -e script testfile.txt
sed: -e expression #1, char 13: Unterminated `s' command
Run Code Online (Sandbox Code Playgroud)
谁能帮我?
谢谢