Index: libcfa/src/concurrency/monitor.cfa
===================================================================
--- libcfa/src/concurrency/monitor.cfa	(revision 3b21c9689f76fa7dd6b57be3084a8e37ab0d7809)
+++ libcfa/src/concurrency/monitor.cfa	(revision f6f7b52253f062a95819b4226c6f6f95b28a2ac9)
@@ -9,7 +9,7 @@
 // Author           : Thierry Delisle
 // Created On       : Thd Feb 23 12:27:26 2017
-// Last Modified By : Peter A. Buhr
-// Last Modified On : Wed Nov 27 12:13:14 2024
-// Update Count     : 72
+// Last Modified By : Kyoung Seo
+// Last Modified On : Thd Jan 16 12:59:00 2025
+// Update Count     : 73
 //
 
@@ -922,37 +922,9 @@
 static inline [thread$ *, int] search_entry_queue( const __waitfor_mask_t & mask, monitor$ * monitors [], __lock_size_t count ) {
 	__queue_t(thread$) & entry_queue = monitors[0]->entry_queue;
-
-#if 0
-	#if defined( __CFA_WITH_VERIFY__ )
-		thread$ * last = 0p;
-	#endif
-	// For each thread in the entry-queue
-	for ( thread$ ** thrd_it = &entry_queue.head; (*thrd_it) != 1p; thrd_it = &get_next(**thrd_it) ) {
-		thread$ * curr = *thrd_it;
-
-		/* paranoid */ verifyf( !last || last->user_link.next == curr, "search not making progress, from %p (%p) to %p",
-								last, last->user_link.next, curr );
-		/* paranoid */ verifyf( curr != last, "search not making progress, from %p to %p", last, curr );
-
-		// For each acceptable check if it matches
-		int i = 0;
-		__acceptable_t * end = end(mask);
-		__acceptable_t * begin = begin(mask);
-		for ( __acceptable_t * it = begin; it != end; it++, i++ ) {
-			// Check for match
-			if ( *it == curr->monitors ) {
-				// If match, return it after removeing it from the entry queue
-				return [remove( entry_queue, thrd_it ), i];
-			}
-		}
-
-		#if defined( __CFA_WITH_VERIFY__ )
-			last = curr;
-		#endif
-	}
-#else
 	// For each acceptable (respect lexical priority in waitfor statement)
-	__acceptable_t * it = end(mask); it--;				// end is passed the last node, so backup
-	for ( int i = mask.size - 1; i >= 0; i -= 1, it-- ) {
+	int i = 0;
+	__acceptable_t * end = end(mask);
+	__acceptable_t * begin = begin(mask);
+	for ( __acceptable_t * it = begin; it != end; it++, i++ ) {
 		#if defined( __CFA_WITH_VERIFY__ )
 		thread$ * last = 0p;
@@ -977,5 +949,4 @@
 		} // for
 	} // for
-#endif
 	return [0, -1];
 }
Index: src/Parser/StatementNode.cpp
===================================================================
--- src/Parser/StatementNode.cpp	(revision 3b21c9689f76fa7dd6b57be3084a8e37ab0d7809)
+++ src/Parser/StatementNode.cpp	(revision f6f7b52253f062a95819b4226c6f6f95b28a2ac9)
@@ -10,7 +10,7 @@
 // Author           : Rodolfo G. Esteves
 // Created On       : Sat May 16 14:59:41 2015
-// Last Modified By : Peter A. Buhr
-// Last Modified On : Mon Sep 23 22:50:35 2024
-// Update Count     : 432
+// Last Modified By : Kyoung Seo
+// Last Modified On : Thd Jan 16 13:05:00 2025
+// Update Count     : 433
 //
 
@@ -351,5 +351,5 @@
 	delete targetExpr;
 
-	existing->clauses.insert( existing->clauses.begin(), clause );
+	existing->clauses.insert( existing->clauses.end(), clause );
 
 	return existing;
Index: tests/concurrency/waitfor/.expect/lexical_priority.txt
===================================================================
--- tests/concurrency/waitfor/.expect/lexical_priority.txt	(revision f6f7b52253f062a95819b4226c6f6f95b28a2ac9)
+++ tests/concurrency/waitfor/.expect/lexical_priority.txt	(revision f6f7b52253f062a95819b4226c6f6f95b28a2ac9)
@@ -0,0 +1,2 @@
+f f f f f f f f f f f f f f f f f f f f f f f f f g g g g g g g g g g g g g g g g g g g g g g g g g
+f f f f f f f f f f f f f f f f f f f f f f f f f g g g g g g g g g g g g g g g g g g g g g g g g g
Index: tests/concurrency/waitfor/lexical_priority.cfa
===================================================================
--- tests/concurrency/waitfor/lexical_priority.cfa	(revision f6f7b52253f062a95819b4226c6f6f95b28a2ac9)
+++ tests/concurrency/waitfor/lexical_priority.cfa	(revision f6f7b52253f062a95819b4226c6f6f95b28a2ac9)
@@ -0,0 +1,47 @@
+#include <thread.hfa>
+#include <fstream.hfa>
+
+// Test priority order of waitfor clauses. To get deterministic output for repeatable testing, preemption is disabled
+// and the threads defer to each other at certain points.
+
+Duration default_preemption() {	return 0; }				// disable preemption
+
+enum { Times = 50, Half = Times / 2 };
+
+thread T {};
+void f( T & mutex ) {}
+void g( T & mutex ) {}
+void main( T & t ) {
+	sout | nlOff;
+	for ( Times / Half ) {
+		for ( Half ) {
+			waitfor( f : t ) sout | "f";
+			or waitfor( g :t ) sout | "g";				// service f before g
+		} // for
+		for ( Half ) {
+			waitfor( g : t ) sout | "g";				// service g before f
+			or waitfor( f : t )	sout | "f";
+		} // for
+		sout | "\n";
+	} // for
+}
+
+T t;													// shared
+
+thread F{};
+void main( F & ) {
+	for ( Half ) f( t );
+	yield( 5 ); 										// let g get ahead
+	for ( Half ) f( t );
+}
+thread G{};
+void main( G & ) {
+	yield( 5 ); 										// let f get ahead
+	for ( Half ) g( t );
+	for ( Half ) g( t );
+}
+
+int main() {
+	F f;
+	G g;
+}
