The OpenD Programming Language

1 /**
2  * The thread module provides support for thread creation and management.
3  *
4  * Copyright: Copyright Sean Kelly 2005 - 2012.
5  * License: Distributed under the
6  *      $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0).
7  *    (See accompanying file LICENSE)
8  * Authors:   Sean Kelly, Walter Bright, Alex Rønne Petersen, Martin Nowak
9  * Source:    $(DRUNTIMESRC core/thread/package.d)
10  */
11 
12 module core.thread;
13 
14 public import core.time;
15 public import core.thread.fiber;
16 public import core.thread.osthread;
17 public import core.thread.threadbase;
18 public import core.thread.threadgroup;
19 public import core.thread.types;
20 public import core.thread.context;
21 
22 
23 // this test is here to avoid a cyclic dependency between
24 // core.thread and core.atomic
25 unittest
26 {
27     import core.atomic;
28 
29     // Use heap memory to ensure an optimizing
30     // compiler doesn't put things in registers.
31     uint* x = new uint();
32     bool* f = new bool();
33     uint* r = new uint();
34 
35     auto thr = new Thread(()
36     {
37         while (!*f)
38         {
39         }
40 
41         atomicFence();
42 
43         *r = *x;
44     });
45 
46     thr.start();
47 
48     *x = 42;
49 
50     atomicFence();
51 
52     *f = true;
53 
54     atomicFence();
55 
56     thr.join();
57 
58     assert(*r == 42);
59 }