Index: doc/theses/thierry_delisle_PhD/code/readyQ_proto/work_stealing.hpp
===================================================================
--- doc/theses/thierry_delisle_PhD/code/readyQ_proto/work_stealing.hpp	(revision a1b9bc32a15e98b204ca26969764c493704517ea)
+++ doc/theses/thierry_delisle_PhD/code/readyQ_proto/work_stealing.hpp	(revision 634a5c2cfc247bd35869699a7cb6837b3cff9483)
@@ -15,5 +15,5 @@
 #include "snzi.hpp"
 
-#include <x86intrin.h>
+// #include <x86intrin.h>
 
 using namespace std;
@@ -28,7 +28,16 @@
 template<typename node_t>
 struct __attribute__((aligned(128))) localQ_t {
-	mpsc_queue<node_t> queue = {};
-	spinlock_t lock = {};
-	bool needs_help = true;
+	// volatile unsigned long long val = 0;
+	// mpsc_queue<node_t> queue = {};
+	// spinlock_t lock = {};
+	intrusive_queue_t<node_t> list;
+
+	inline auto ts() { return list.ts(); }
+	inline auto lock() { return list.lock.lock(); }
+	inline auto try_lock() { return list.lock.try_lock(); }
+	inline auto unlock() { return list.lock.unlock(); }
+
+	inline auto push( node_t * node ) { return list.push( node ); }
+	inline auto pop() { return list.pop(); }
 };
 
@@ -44,5 +53,6 @@
 	work_stealing(unsigned _numThreads, unsigned)
 		: numThreads(_numThreads * nqueues)
-		, lists(new intrusive_queue_t<node_t>[numThreads])
+		, lists(new localQ_t<node_t>[numThreads])
+		// , lists(new intrusive_queue_t<node_t>[numThreads])
 		, times(new timestamp_t[numThreads])
 		// , snzi( std::log2( numThreads / 2 ), 2 )
@@ -58,6 +68,6 @@
 
 	__attribute__((noinline, hot)) void push(node_t * node) {
-		// node->_links.ts = rdtscl();
-		node->_links.ts = 1;
+		node->_links.ts = rdtscl();
+		// node->_links.ts = 1;
 
 		auto & list = *({
@@ -72,10 +82,10 @@
 					i = tls.my_queue + (r % nqueues);
 				}
-			} while(!lists[i].lock.try_lock());
+			} while(!lists[i].try_lock());
 		 	&lists[i];
 		});
 
 		list.push( node );
-		list.lock.unlock();
+		list.unlock();
 		// tls.rng2.set_raw_state( tls.rng1.get_raw_state());
 		// count++;
@@ -84,17 +94,35 @@
 
 	__attribute__((noinline, hot)) node_t * pop() {
-		if( tls.myfriend == outside ) {
-			auto r  = tls.rng1.next();
-			tls.myfriend = r % numThreads;
-			times[tls.myfriend].val = 0;
-		}
-		else if(times[tls.myfriend].val == 0) {
-			node_t * n = try_pop(tls.myfriend, tls.stats.pop.help);
-			tls.stats.help++;
-			tls.myfriend = outside;
-			if(n) return n;
-		}
-
 		if(tls.my_queue != outside) {
+			if( tls.myfriend == outside ) {
+				auto r  = tls.rng1.next();
+				tls.myfriend = r % numThreads;
+				tls.mytime = lists[(tls.it % nqueues) + tls.my_queue].ts();
+				// times[tls.myfriend].val = 0;
+				// lists[tls.myfriend].val = 0;
+			}
+			// else if(times[tls.myfriend].val == 0) {
+			// else if(lists[tls.myfriend].val == 0) {
+			else if(times[tls.myfriend].val < tls.mytime) {
+			// else if(times[tls.myfriend].val < lists[(tls.it % nqueues) + tls.my_queue].ts()) {
+				node_t * n = try_pop(tls.myfriend, tls.stats.pop.help);
+				tls.stats.help++;
+				tls.myfriend = outside;
+				if(n) return n;
+			}
+			// if( tls.myfriend == outside ) {
+			// 	auto r  = tls.rng1.next();
+			// 	tls.myfriend = r % numThreads;
+			// 	tls.mytime = lists[((tls.it + 1) % nqueues) + tls.my_queue].ts();
+			// }
+			// else {
+			// 	if(times[tls.myfriend].val + 1000 < tls.mytime) {
+			// 		node_t * n = try_pop(tls.myfriend, tls.stats.pop.help);
+			// 		tls.stats.help++;
+			// 		if(n) return n;
+			// 	}
+			// 	tls.myfriend = outside;
+			// }
+
 			node_t * n = local();
 			if(n) return n;
@@ -112,5 +140,4 @@
 private:
 	inline node_t * local() {
-		// unsigned i = (tls.rng2.prev() % 4) + tls.my_queue;
 		unsigned i = (--tls.it % nqueues) + tls.my_queue;
 		return try_pop(i, tls.stats.pop.local);
@@ -153,10 +180,9 @@
 
 		// If we can't get the lock, move on
-		if( !list.lock.try_lock() ) { stat.elock++; return nullptr; }
-
+		if( !list.try_lock() ) { stat.elock++; return nullptr; }
 
 		// If list is empty, unlock and retry
 		if( list.ts() == 0 ) {
-			list.lock.unlock();
+			list.unlock();
 			stat.eempty++;
 			return nullptr;
@@ -164,9 +190,9 @@
 
 		auto node = list.pop();
-		list.lock.unlock();
+		list.unlock();
 		stat.success++;
-		times[i].val = 1; //node.first->_links.ts;
-		// count--;
-		// _mm_stream_si64((long long int*)&times[i].val, node.first->_links.ts);
+		// times[i].val = 1;
+		times[i].val = node.first->_links.ts;
+		// lists[i].val = node.first->_links.ts;
 		return node.first;
 	}
@@ -191,4 +217,5 @@
 		unsigned   my_queue = calc_preferred();
 		unsigned   myfriend = outside;
+		unsigned long long int mytime = 0;
 		#if defined(READ)
 			unsigned it = 0;
@@ -211,5 +238,6 @@
 private:
 	const unsigned numThreads;
-    	std::unique_ptr<intrusive_queue_t<node_t> []> lists;
+    	std::unique_ptr<localQ_t<node_t> []> lists;
+    	// std::unique_ptr<intrusive_queue_t<node_t> []> lists;
     	std::unique_ptr<timestamp_t []> times;
 	__attribute__((aligned(128))) std::atomic_size_t count;
