小编Hei*_*Ody的帖子

Java中的奇怪行为,在多线程程序中使用非同步访问

我更改了一个值,用于确定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)

java concurrency

5
推荐指数
1
解决办法
111
查看次数

Haskell - 类型/模式匹配

以下代码无法编译.我收到类型错误.我认为这将是更好的版本,因为它清楚地分离了两种不同的情况......该函数应该有助于确定有限状态机是否接受输入字.

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)

haskell types pattern-matching

0
推荐指数
1
解决办法
139
查看次数

标签 统计

concurrency ×1

haskell ×1

java ×1

pattern-matching ×1

types ×1