BUG/MINOR: threads: Handle nbthread == MAX_THREADS.

If nbthread is MAX_THREADS, the shift operation needed to compute
all_threads_mask fails in thread_sync_init(). Instead pass a number
of threads to this function and let it compute the mask without
overflowing.

This should be backported to 1.8.
diff --git a/src/hathreads.c b/src/hathreads.c
index fa9993b..c0c5956 100644
--- a/src/hathreads.c
+++ b/src/hathreads.c
@@ -37,11 +37,11 @@
 struct lock_stat lock_stats[LOCK_LABELS];
 #endif
 
-/* Initializes the sync point. It creates a pipe used by threads to wakup all
- * others when a sync is requested. It also initialize the mask of all create
+/* Initializes the sync point. It creates a pipe used by threads to wake up all
+ * others when a sync is requested. It also initializes the mask of all created
  * threads. It returns 0 on success and -1 if an error occurred.
  */
-int thread_sync_init(unsigned long mask)
+int thread_sync_init(int nbthread)
 {
 	int rfd;
 
@@ -52,7 +52,9 @@
 	fcntl(rfd, F_SETFL, O_NONBLOCK);
 	fd_insert(rfd, thread_sync_io_handler, thread_sync_io_handler, MAX_THREADS_MASK);
 
-	all_threads_mask = mask;
+	/* we proceed like this to be sure never to overflow the left shift */
+	all_threads_mask = 1UL << (nbthread - 1);
+	all_threads_mask |= all_threads_mask - 1;
 	return 0;
 }