Revert barrier-based LSan threading race workaround

The extra "barrier" approach was too much code whose sole purpose was to work around a race that is not even ours (i.e. in LSan's teardown code). In preparation for queuing a solution taking a much-less-invasive approach, let's revert them.

Junio C Hamano committed Jan 1, 2025 at 14:13 UTC fc89d14c639faec779956b4e3cd873c07bd4327b
5 files changed -39
Makefile
-7
@@ -141,10 +141,6 @@ include shared.mak
141 #
142 # Define NO_PTHREADS if you do not have or do not want to use Pthreads.
143 #
144 -# Define THREAD_BARRIER_PTHREAD if your system has pthread_barrier_t. Barrier
145 -# support is optional and is only helpful when building with SANITIZE=leak, as
146 -# it is used to eliminate some races in the leak-checker.
147 -#
144 # Define NO_PREAD if you have a problem with pread() system call (e.g.
145 # cygwin1.dll before v1.5.22).
146 #
@@ -2083,9 +2079,6 @@ ifdef NO_PTHREADS
2079 else
2080 BASIC_CFLAGS += $(PTHREAD_CFLAGS)
2081 EXTLIBS += $(PTHREAD_LIBS)
2086 - ifdef THREAD_BARRIER_PTHREAD
2087 - BASIC_CFLAGS += -DTHREAD_BARRIER_PTHREAD
2088 - endif
2082 endif
2083
2084 ifdef HAVE_PATHS_H
builtin/grep.c
-8
@@ -101,9 +101,6 @@ static pthread_cond_t cond_write;
101 /* Signalled when we are finished with everything. */
102 static pthread_cond_t cond_result;
103
104 -/* Synchronize the start of all threads */
105 -static maybe_thread_barrier_t start_barrier;
106 -
104 static int skip_first_line;
105
106 static void add_work(struct grep_opt *opt, struct grep_source *gs)
@@ -201,8 +198,6 @@ static void *run(void *arg)
198 int hit = 0;
199 struct grep_opt *opt = arg;
200
204 - maybe_thread_barrier_wait(&start_barrier);
205 -
201 while (1) {
202 struct work_item *w = get_work();
203 if (!w)
@@ -234,7 +229,6 @@ static void start_threads(struct grep_opt *opt)
229 pthread_cond_init(&cond_add, NULL);
230 pthread_cond_init(&cond_write, NULL);
231 pthread_cond_init(&cond_result, NULL);
237 - maybe_thread_barrier_init(&start_barrier, NULL, num_threads + 1);
232 grep_use_locks = 1;
233 enable_obj_read_lock();
234
@@ -254,7 +248,6 @@ static void start_threads(struct grep_opt *opt)
248 die(_("grep: failed to create thread: %s"),
249 strerror(err));
250 }
257 - maybe_thread_barrier_wait(&start_barrier);
251 }
252
253 static int wait_all(void)
@@ -291,7 +284,6 @@ static int wait_all(void)
284 pthread_cond_destroy(&cond_add);
285 pthread_cond_destroy(&cond_write);
286 pthread_cond_destroy(&cond_result);
294 - maybe_thread_barrier_destroy(&start_barrier);
287 grep_use_locks = 0;
288 disable_obj_read_lock();
289
builtin/index-pack.c
-6
@@ -185,8 +185,6 @@ static pthread_mutex_t deepest_delta_mutex;
185
186 static pthread_key_t key;
187
188 -static maybe_thread_barrier_t start_barrier;
189 -
188 static inline void lock_mutex(pthread_mutex_t *mutex)
189 {
190 if (threads_active)
@@ -211,7 +209,6 @@ static void init_thread(void)
209 if (show_stat)
210 pthread_mutex_init(&deepest_delta_mutex, NULL);
211 pthread_key_create(&key, NULL);
214 - maybe_thread_barrier_init(&start_barrier, NULL, nr_threads);
212 CALLOC_ARRAY(thread_data, nr_threads);
213 for (i = 0; i < nr_threads; i++) {
214 thread_data[i].pack_fd = xopen(curr_pack, O_RDONLY);
@@ -234,7 +231,6 @@ static void cleanup_thread(void)
231 for (i = 0; i < nr_threads; i++)
232 close(thread_data[i].pack_fd);
233 pthread_key_delete(key);
237 - maybe_thread_barrier_destroy(&start_barrier);
234 free(thread_data);
235 }
236
@@ -1104,8 +1100,6 @@ static int compare_ref_delta_entry(const void *a, const void *b)
1100
1101 static void *threaded_second_pass(void *data)
1102 {
1107 - if (threads_active)
1108 - maybe_thread_barrier_wait(&start_barrier);
1103 if (data)
1104 set_thread_data(data);
1105 for (;;) {
ci/lib.sh
-1
@@ -385,7 +385,6 @@ linux-musl)
385 ;;
386 linux-leaks|linux-reftable-leaks)
387 export SANITIZE=leak
388 - export THREAD_BARRIER_PTHREAD=1
388 ;;
389 linux-asan-ubsan)
390 export SANITIZE=address,undefined
thread-utils.h
-17
@@ -53,22 +53,5 @@ int dummy_pthread_init(void *);
53 int online_cpus(void);
54 int init_recursive_mutex(pthread_mutex_t*);
55
56 -#ifdef THREAD_BARRIER_PTHREAD
57 -#define maybe_thread_barrier_t pthread_barrier_t
58 -#define maybe_thread_barrier_init pthread_barrier_init
59 -#define maybe_thread_barrier_wait pthread_barrier_wait
60 -#define maybe_thread_barrier_destroy pthread_barrier_destroy
61 -#else
62 -#define maybe_thread_barrier_t int
63 -static inline int maybe_thread_barrier_init(maybe_thread_barrier_t *b UNUSED,
64 - void *attr UNUSED,
65 - unsigned nr UNUSED)
66 -{
67 - errno = ENOSYS;
68 - return -1;
69 -}
70 -#define maybe_thread_barrier_wait(barrier)
71 -#define maybe_thread_barrier_destroy(barrier)
72 -#endif
56
57 #endif /* THREAD_COMPAT_H */