我更改了一个值,用于确定while循环何时在单独的线程中终止.
我不想知道如何使这个工作.如果我只通过synchronized getters/setters访问变量测试,它按预期工作.
我原以为,如果一些读/写命令由于并发而丢失,程序有时不会终止,但它永远不会.这让我感到困惑..
我想知道为什么程序永远不会终止,没有print-command.我想了解为什么print-command会改变任何东西..
public class CustomComboBoxDemo {
public static boolean test = true;
public static void main(String[] args) {
Thread user =new Thread(){
@Override
public void run(){
try {
sleep(2000);
} catch (InterruptedException e) {}
test=false;
}
};
user.start();
while(test) {
System.out.println("foo"); //Without this line the program does not terminate..
}
}
}
Run Code Online (Sandbox Code Playgroud) 以下代码无法编译.我收到类型错误.我认为这将是更好的版本,因为它清楚地分离了两种不同的情况......该函数应该有助于确定有限状态机是否接受输入字.
import Text.Show.Functions
import qualified Data.Set as Set
import qualified Data.List as List
setTransition :: (Int -> Char -> [Int]) -> [Int] -> Char -> [Int]
setTransition delta [] sigma = []
setTransition delta xs@[x:xs'] sigma = foldl f [] xs
where f ys q = (delta q sigma) `List.union` ys
Run Code Online (Sandbox Code Playgroud)
然而,这(删除了模式匹配)会编译.谁能告诉我为什么?
import Text.Show.Functions
import qualified Data.Set as Set
import qualified Data.List as List
setTransition :: (Int -> Char -> [Int]) -> [Int] -> Char -> [Int]
setTransition delta [] …Run Code Online (Sandbox Code Playgroud)