Index: configure
===================================================================
--- configure	(revision dd020c0cdff72537d5b1dffcf6920c72db9d585a)
+++ configure	(revision 81912032b17ba009d0af2f3c783bdf37fc024161)
@@ -3131,5 +3131,5 @@
 if test "${enable_threading+set}" = set; then :
   enableval=$enable_threading; case "${enableval}" in
-  yes) build_threading-"yes" ;;
+  yes) build_threading="yes" ;;
   no)  build_threading="no" ;;
   *) as_fn_error $? "bad value ${enableval} for --enable-debug" "$LINENO" 5 ;;
Index: configure.ac
===================================================================
--- configure.ac	(revision dd020c0cdff72537d5b1dffcf6920c72db9d585a)
+++ configure.ac	(revision 81912032b17ba009d0af2f3c783bdf37fc024161)
@@ -59,5 +59,5 @@
 AC_ARG_ENABLE(threading, AS_HELP_STRING([--enable-threading], [Build and install libcfa with threading support (Enabled by default)]),
 [case "${enableval}" in
-  yes) build_threading-"yes" ;;
+  yes) build_threading="yes" ;;
   no)  build_threading="no" ;;
   *) AC_MSG_ERROR([bad value ${enableval} for --enable-debug]) ;;
Index: doc/proposals/flags.md
===================================================================
--- doc/proposals/flags.md	(revision 81912032b17ba009d0af2f3c783bdf37fc024161)
+++ doc/proposals/flags.md	(revision 81912032b17ba009d0af2f3c783bdf37fc024161)
@@ -0,0 +1,78 @@
+## Flag Enums ##
+
+A common programming problem is to represent a value from a set of boolean flags, each of which can be either on or off. C already has enums and bitfields, which can be naturally used to represent the individual flags, but are un-ergonomic to combine together. This proposal introduces "flag enums", a variant of the usual enums specialized to represent flags in a more ergonomic way.
+
+As an example, a flag enum for the TCP control bits could be defined as follows:
+
+	```
+	enum TCP_Flags {
+		FIN,
+		SYN,
+		RST,
+		PSH,
+		ACK,
+		URG,
+		ECE,
+		CWR,
+		NS
+	} __attribute__((flag));
+	```
+
+The `__attribute__` syntax is ugly, but represents the smallest backwards compatibility break; a new SUE for enum flags (e.g. `flag enum TCP_Flags { ... };` or even `flag TCP_Flags { ... };`) might also be reasonable.
+
+A flag enum would be different than a normal enum in two ways: it would auto-generate discriminant values differently, and it would have a number of bitwise operators defined on it by default.
+
+Normal enums generate their discriminant values sequentially starting at zero (`0, 1, 2, 3, ...`), while a flag enum would generate its discriminant values as successive powers of two starting at `1`. E.g. the `TCP_Flags` declaration above would codegen to an enum like below:
+
+	```
+	enum TCP_Flags {
+		FIN = 0x1,
+		SYN = 0x2,
+		RST = 0x4,
+		PSH = 0x8,
+		ACK = 0x10,
+		URG = 0x20,
+		ECE = 0x40,
+		CWR = 0x80,
+		NS = 0x100
+	};
+	```
+
+The precise rule used would be that if no enum discriminant is given, the discriminant is the smallest power of two larger than the previous discriminant (`1` if there is no previous discriminant). This would allow some flexibility for cases like these:
+
+	```
+	enum FunFlags {
+		NONE = 0,           // Named empty value
+		FOO,  // == 0x1
+		BAZ = 0x6,          // Multi-bit flag: 0x4 | 0x2
+		BAR,  // == 0x8
+		FOOBAR = FOO | BAR  // Named combination flag
+	} __attribute__((flag));
+	```
+
+Secondly, we would auto-generate a number of useful operators for any flag enum, as follows:
+* The default constructor for any flag enum would be defined, and would produce a flag with an underlying value of 0.
+* Assignment from and equality/inequality to `zero_t` should also be defined based on the underlying enum value.
+* The bitwise operators `?&?, ?|?, ?^?, ~?` and their assignment variants `?&=?, ?|=?, ?^=?` shall be defined with the semantics of the underlying enum value; `?-?` and `?-=?` should also be defined such that `a - b == a & ~b` (a set difference operation).
+
+With these operations defined, flag enums would support a full set of useful flag operations, using existing, known syntax, as follows:
+
+	```
+	FunFlags f = some_val();
+	if ( f ) { sout | "f has some flag(s) set" | endl; }
+	if ( f & FOO ) { sout | "f has FOO set" | endl; }
+	f |= FOO; // set FOO
+	f -= FOO; // unset FOO
+	f ^= FOO; // toggle FOO
+	```
+
+In each of the cases above, `FOO` could be replaced by `(BAR | BAZ)` to do the same operation or test on multiple flags at once.
+
+### Related Work ###
+C# has the [`[Flags]`][1] enum attribute, but their proposal does not go as far; specifically, the flag discriminants must be manually specified, and they do not automatically implement the bitwise operators on the flags. 
+
+Java has [`EnumSet`][2] which represents the set of flags for a given enum (C++ [`bitset`][3] can be used similarly). The main disadvantage of applying this approach to Cforall is that C enum types already implicitly convert to int, and the bitwise operators already have interpretations on enums with `int` results based on this conversion. As such, all flags need to be wrapped in a set to be used type-safely with the bitwise operators.
+
+[1]: https://msdn.microsoft.com/en-us/library/system.enum.hasflag(v=vs.110).aspx
+[2]: http://docs.oracle.com/javase/7/docs/api/java/util/EnumSet.html
+[3]: http://en.cppreference.com/w/cpp/utility/bitset
Index: src/CodeTools/DeclStats.cc
===================================================================
--- src/CodeTools/DeclStats.cc	(revision dd020c0cdff72537d5b1dffcf6920c72db9d585a)
+++ src/CodeTools/DeclStats.cc	(revision 81912032b17ba009d0af2f3c783bdf37fc024161)
@@ -200,5 +200,8 @@
 			// skip if already seen declaration for this function
 			const std::string& mangleName = decl->get_mangleName().empty() ? decl->get_name() : decl->get_mangleName();
-			if ( ! seen_names.insert( mangleName ).second ) return;
+			if ( ! seen_names.insert( mangleName ).second ) {
+				maybeAccept( decl->get_statements(), *this );
+				return;
+			}
 			
 			Stats& stats = for_linkage[ decl->get_linkage() ];
@@ -228,4 +231,7 @@
 
 			analyzeFunc( fnTy, stats, stats.params, stats.returns );
+
+			// analyze expressions in decl statements
+			maybeAccept( decl->get_statements(), *this );
 		}
 
Index: src/libcfa/concurrency/monitor
===================================================================
--- src/libcfa/concurrency/monitor	(revision dd020c0cdff72537d5b1dffcf6920c72db9d585a)
+++ src/libcfa/concurrency/monitor	(revision 81912032b17ba009d0af2f3c783bdf37fc024161)
@@ -20,4 +20,5 @@
 #include "assert"
 #include "invoke.h"
+#include "stdlib"
 
 struct __monitor_t {
@@ -33,19 +34,38 @@
 }
 
+//Basic entering routine
 void enter(__monitor_t *);
 void leave(__monitor_t *);
 
+//Array entering routine
+void enter(__monitor_t **, int count);
+void leave(__monitor_t **, int count);
+
 struct monitor_guard_t {
-	__monitor_t * m;
+	__monitor_t ** m;
+	int count;
 };
 
-static inline void ?{}( monitor_guard_t * this, __monitor_t * m ) {
+static inline int ?<?(__monitor_t* lhs, __monitor_t* rhs) {
+	return ((intptr_t)lhs) < ((intptr_t)rhs);
+}
+
+static inline void ?{}( monitor_guard_t * this, __monitor_t ** m ) {
 	this->m = m;
-	enter( this->m );
+	this->count = 1;
+	enter( *this->m );
+}
+
+static inline void ?{}( monitor_guard_t * this, __monitor_t ** m, int count ) {
+	this->m = m;
+	this->count = count;
+	qsort(this->m, count);
+	enter( this->m, this->count );
 }
 
 static inline void ^?{}( monitor_guard_t * this ) {
-	leave( this->m );
+	leave( this->m, this->count );
 }
 
+
 #endif //MONITOR_H
Index: src/libcfa/concurrency/monitor.c
===================================================================
--- src/libcfa/concurrency/monitor.c	(revision dd020c0cdff72537d5b1dffcf6920c72db9d585a)
+++ src/libcfa/concurrency/monitor.c	(revision 81912032b17ba009d0af2f3c783bdf37fc024161)
@@ -71,2 +71,16 @@
 	}
 }
+
+void enter(__monitor_t ** monitors, int count) {
+	for(int i = 0; i < count; i++) {
+		// printf("%d\n", i);
+		enter( monitors[i] );
+	}
+}
+
+void leave(__monitor_t ** monitors, int count) {
+	for(int i = count - 1; i >= 0; i--) {
+		// printf("%d\n", i);
+		leave( monitors[i] );
+	}
+}
Index: src/tests/.expect/concurrent/coroutine.txt
===================================================================
--- src/tests/.expect/concurrent/coroutine.txt	(revision 81912032b17ba009d0af2f3c783bdf37fc024161)
+++ src/tests/.expect/concurrent/coroutine.txt	(revision 81912032b17ba009d0af2f3c783bdf37fc024161)
@@ -0,0 +1,10 @@
+0 0
+1 1
+1 1
+2 2
+3 3
+5 5
+8 8
+13 13
+21 21
+34 34
Index: src/tests/.expect/concurrent/monitor.txt
===================================================================
--- src/tests/.expect/concurrent/monitor.txt	(revision 81912032b17ba009d0af2f3c783bdf37fc024161)
+++ src/tests/.expect/concurrent/monitor.txt	(revision 81912032b17ba009d0af2f3c783bdf37fc024161)
@@ -0,0 +1,1 @@
+4000000
Index: src/tests/.expect/concurrent/multi-monitor.txt
===================================================================
--- src/tests/.expect/concurrent/multi-monitor.txt	(revision 81912032b17ba009d0af2f3c783bdf37fc024161)
+++ src/tests/.expect/concurrent/multi-monitor.txt	(revision 81912032b17ba009d0af2f3c783bdf37fc024161)
@@ -0,0 +1,1 @@
+2000000 2000000 2000000
Index: src/tests/.expect/concurrent/thread.txt
===================================================================
--- src/tests/.expect/concurrent/thread.txt	(revision 81912032b17ba009d0af2f3c783bdf37fc024161)
+++ src/tests/.expect/concurrent/thread.txt	(revision 81912032b17ba009d0af2f3c783bdf37fc024161)
@@ -0,0 +1,22 @@
+User main begin
+First : Suspend No. 1
+First : Suspend No. 2
+First : Suspend No. 3
+First : Suspend No. 4
+First : Suspend No. 5
+First : Suspend No. 6
+First : Suspend No. 7
+First : Suspend No. 8
+First : Suspend No. 9
+First : Suspend No. 10
+Second : Suspend No. 1
+Second : Suspend No. 2
+Second : Suspend No. 3
+Second : Suspend No. 4
+Second : Suspend No. 5
+Second : Suspend No. 6
+Second : Suspend No. 7
+Second : Suspend No. 8
+Second : Suspend No. 9
+Second : Suspend No. 10
+User main end
Index: c/tests/.expect/coroutine.txt
===================================================================
--- src/tests/.expect/coroutine.txt	(revision dd020c0cdff72537d5b1dffcf6920c72db9d585a)
+++ 	(revision )
@@ -1,10 +1,0 @@
-0 0
-1 1
-1 1
-2 2
-3 3
-5 5
-8 8
-13 13
-21 21
-34 34
Index: c/tests/.expect/monitor.txt
===================================================================
--- src/tests/.expect/monitor.txt	(revision dd020c0cdff72537d5b1dffcf6920c72db9d585a)
+++ 	(revision )
@@ -1,1 +1,0 @@
-4000000
Index: c/tests/.expect/thread.txt
===================================================================
--- src/tests/.expect/thread.txt	(revision dd020c0cdff72537d5b1dffcf6920c72db9d585a)
+++ 	(revision )
@@ -1,22 +1,0 @@
-User main begin
-First : Suspend No. 1
-First : Suspend No. 2
-First : Suspend No. 3
-First : Suspend No. 4
-First : Suspend No. 5
-First : Suspend No. 6
-First : Suspend No. 7
-First : Suspend No. 8
-First : Suspend No. 9
-First : Suspend No. 10
-Second : Suspend No. 1
-Second : Suspend No. 2
-Second : Suspend No. 3
-Second : Suspend No. 4
-Second : Suspend No. 5
-Second : Suspend No. 6
-Second : Suspend No. 7
-Second : Suspend No. 8
-Second : Suspend No. 9
-Second : Suspend No. 10
-User main end
Index: src/tests/Makefile.am
===================================================================
--- src/tests/Makefile.am	(revision dd020c0cdff72537d5b1dffcf6920c72db9d585a)
+++ src/tests/Makefile.am	(revision 81912032b17ba009d0af2f3c783bdf37fc024161)
@@ -17,4 +17,14 @@
 debug=yes
 
+quick_test=vector_test avl_test operators numericConstants expression enum array typeof cast dtor-early-exit init_once
+
+if BUILD_CONCURRENCY
+concurrent=yes
+quick_test+= coroutine thread monitor
+else
+concurrent=no
+endif
+
+
 # applies to both programs
 EXTRA_FLAGS =
@@ -30,8 +40,8 @@
 
 all-local :
-	@+python test.py vector_test avl_test operators numericConstants expression enum array typeof cast dtor-early-exit init_once coroutine thread
+	@+python test.py --debug=${debug} --concurrent=${concurrent} ${quick_test}
 
 all-tests :
-	@+python test.py --all --debug=${debug}		# '@' => do not echo command (SILENT), '+' => allows recursive make from within python program
+	@+python test.py --all --debug=${debug} --concurrent=${concurrent}		# '@' => do not echo command (SILENT), '+' => allows recursive make from within python program
 
 clean-local :
@@ -39,5 +49,5 @@
 
 list :
-	@+python test.py --list
+	@+python test.py --list --concurrent=${concurrent}
 
 constant0-1DP : constant0-1.c
Index: src/tests/Makefile.in
===================================================================
--- src/tests/Makefile.in	(revision dd020c0cdff72537d5b1dffcf6920c72db9d585a)
+++ src/tests/Makefile.in	(revision 81912032b17ba009d0af2f3c783bdf37fc024161)
@@ -37,4 +37,5 @@
 build_triplet = @build@
 host_triplet = @host@
+@BUILD_CONCURRENCY_TRUE@am__append_1 = coroutine thread monitor
 EXTRA_PROGRAMS = fstream_test$(EXEEXT) vector_test$(EXEEXT) \
 	avl_test$(EXEEXT) constant0-1DP$(EXEEXT) \
@@ -222,4 +223,9 @@
 top_srcdir = @top_srcdir@
 debug = yes
+quick_test = vector_test avl_test operators numericConstants \
+	expression enum array typeof cast dtor-early-exit init_once \
+	$(am__append_1)
+@BUILD_CONCURRENCY_FALSE@concurrent = no
+@BUILD_CONCURRENCY_TRUE@concurrent = yes
 
 # applies to both programs
@@ -651,8 +657,8 @@
 
 all-local :
-	@+python test.py vector_test avl_test operators numericConstants expression enum array typeof cast dtor-early-exit init_once coroutine thread
+	@+python test.py --debug=${debug} --concurrent=${concurrent} ${quick_test}
 
 all-tests :
-	@+python test.py --all --debug=${debug}		# '@' => do not echo command (SILENT), '+' => allows recursive make from within python program
+	@+python test.py --all --debug=${debug} --concurrent=${concurrent}		# '@' => do not echo command (SILENT), '+' => allows recursive make from within python program
 
 clean-local :
@@ -660,5 +666,5 @@
 
 list :
-	@+python test.py --list
+	@+python test.py --list --concurrent=${concurrent}
 
 constant0-1DP : constant0-1.c
Index: src/tests/monitor.c
===================================================================
--- src/tests/monitor.c	(revision dd020c0cdff72537d5b1dffcf6920c72db9d585a)
+++ src/tests/monitor.c	(revision 81912032b17ba009d0af2f3c783bdf37fc024161)
@@ -16,9 +16,10 @@
 
 void increment( /*mutex*/ global_t * this ) {
-	monitor_guard_t g1 = { &this->m };
+	__monitor_t * mon = &this->m;
+	monitor_guard_t g1 = { &mon };
 	{
-		monitor_guard_t g2 = { &this->m };
+		monitor_guard_t g2 = { &mon };
 		{
-			monitor_guard_t g3 = { &this->m };
+			monitor_guard_t g3 = { &mon };
 			this->value += 1;
 		}
Index: src/tests/multi-monitor.c
===================================================================
--- src/tests/multi-monitor.c	(revision 81912032b17ba009d0af2f3c783bdf37fc024161)
+++ src/tests/multi-monitor.c	(revision 81912032b17ba009d0af2f3c783bdf37fc024161)
@@ -0,0 +1,50 @@
+#include <fstream>
+#include <kernel>
+#include <monitor>
+#include <threads>
+
+static int global12, global23, global13;
+
+static __monitor_t m1, m2, m3;
+
+void increment( /*mutex*/ __monitor_t * p1, /*mutex*/ __monitor_t * p2, int * value ) {
+	__monitor_t * mons[] = { p1, p2 };
+	monitor_guard_t g = { mons, 2 };
+	*value += 1;
+}
+
+struct MyThread { 
+	thread t; 
+	int target;
+};
+
+DECL_THREAD(MyThread);
+
+void ?{}( MyThread * this, int target ) {
+	this->target = target;
+}
+
+void main( MyThread* this ) {
+	for(int i = 0; i < 1000000; i++) {
+		choose(this->target) {
+			case 0: increment( &m1, &m2, &global12 );
+			case 1: increment( &m2, &m3, &global23 );
+			case 2: increment( &m1, &m3, &global13 );
+		}
+	}
+}
+
+int main(int argc, char* argv[]) {
+	processor p;
+	{
+		scoped(MyThread) * f[6];
+		for(int i = 0; i < 6; i++) {
+			f[i] = ((scoped(MyThread) *)malloc()){ i % 3 };
+		}
+
+		for(int i = 0; i < 6; i++) {
+			delete( f[i] );
+		}
+	}
+	sout | global12 | global23 | global13 | endl;
+}
Index: src/tests/test.py
===================================================================
--- src/tests/test.py	(revision dd020c0cdff72537d5b1dffcf6920c72db9d585a)
+++ src/tests/test.py	(revision 81912032b17ba009d0af2f3c783bdf37fc024161)
@@ -32,22 +32,29 @@
 	return re.search("ELF\s([0-9]+)-bit", out).group(1)
 
-# reads the directory ./.expect and indentifies the tests
-def listTests():
-	machineType = getMachineType()
+def listTestsFolder(folder) :
+	path = ('./.expect/%s/' % folder) if folder else './.expect/'
+	subpath = "%s/" % folder if folder else ""
 
 	# tests directly in the .expect folder will always be processed
-	generic_list = map(lambda fname: Test(fname, fname),
-		[splitext(f)[0] for f in listdir('./.expect')
+	return map(lambda fname: Test(fname, subpath + fname),
+		[splitext(f)[0] for f in listdir( path )
 		if not f.startswith('.') and f.endswith('.txt')
 		])
 
+# reads the directory ./.expect and indentifies the tests
+def listTests( concurrent ):
+	machineType = getMachineType()
+
+	# tests directly in the .expect folder will always be processed
+	generic_list = listTestsFolder( "" )
+
 	# tests in the machineType folder will be ran only for the corresponding compiler
-	typed_list = map(lambda fname: Test( fname, "%s/%s" % (machineType, fname) ),
-		[splitext(f)[0] for f in listdir("./.expect/%s" % machineType)
-		if not f.startswith('.') and f.endswith('.txt')
-		])
+	typed_list = listTestsFolder( machineType )
+
+	# tests in the concurrent folder will be ran only if concurrency is enabled
+	concurrent_list = listTestsFolder( "concurrent" ) if concurrent else []
 
 	# append both lists to get
-	return generic_list + typed_list
+	return generic_list + typed_list + concurrent_list;
 
 # helper functions to run terminal commands
@@ -194,5 +201,5 @@
 		sys.stderr.flush()
 		return test_failed
-	
+
 	except KeyboardInterrupt:
 		test_failed = True
@@ -243,4 +250,5 @@
 parser = argparse.ArgumentParser(description='Script which runs cforall tests')
 parser.add_argument('--debug', help='Run all tests in debug or release', type=yes_no, default='no')
+parser.add_argument('--concurrent', help='Run concurrent tests', type=yes_no, default='no')
 parser.add_argument('--dry-run', help='Don\'t run the tests, only output the commands', action='store_true')
 parser.add_argument('--list', help='List all test available', action='store_true')
@@ -261,5 +269,5 @@
 
 # fetch the liest of all valid tests
-allTests = listTests()
+allTests = listTests( options.concurrent )
 
 # if user wants all tests than no other treatement of the test list is required
