小编Int*_*ger的帖子

并发,对象可见性

我试图弄清楚下面的代码是否存在任何潜在的并发问题.具体而言,可见性问题与volatile变量有关.易失性定义为:此变量的值永远不会被线程本地缓存:所有读取和写入将直接进入"主存储器"

public static void main(String [] args)
{
    Test test = new Test();

    // This will always single threaded
    ExecutorService ex = Executors.newSingleThreadExecutor();

    for (int i=0; i<10; ++i)
        ex.execute(test);
}

private static class Test implements Runnable {
    // non volatile variable in question
    private int state = 0;

    @Override
    public void run() {
        // will we always see updated state value? Will updating state value
        // guarantee future run's see the value?
        if (this.state != -1)
            this.state++; …
Run Code Online (Sandbox Code Playgroud)

java concurrency multithreading volatile

7
推荐指数
1
解决办法
938
查看次数

提升精神罗马数字解析器示例

试图学习提升精神和文档中给出的例子让我有点困惑.

参考这段代码:

http://www.boost.org/doc/libs/1_46_1/libs/spirit/example/qi/roman.cpp

特别是这段语法:

        start = eps             [_val = 0] >>
            (
                +lit('M')       [_val += 1000]
                ||  hundreds    [_val += _1]
                ||  tens        [_val += _1]
                ||  ones        [_val += _1]
            )
Run Code Online (Sandbox Code Playgroud)

有人可以向我解释为什么它是+亮('M')而不是*亮('M').因为毕竟不能有零个或多个M与一个或多个M?

c++ boost boost-spirit

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

标签 统计

boost ×1

boost-spirit ×1

c++ ×1

concurrency ×1

java ×1

multithreading ×1

volatile ×1