summaryrefslogtreecommitdiff
path: root/mark.c
diff options
context:
space:
mode:
authorIvan Maidanski <ivmai@mail.ru>2022-05-19 08:02:28 +0300
committerIvan Maidanski <ivmai@mail.ru>2022-05-19 12:20:54 +0300
commita8b96ed7655169757765433dee919824ccc62c36 (patch)
treefc48f9f5ce56ec09d9866cc9ee81c9343f41ddaa /mark.c
parente338ee5fa6057d44308baf69dbb56c118317e493 (diff)
downloadbdwgc-a8b96ed7655169757765433dee919824ccc62c36.tar.gz
Fix potential race if start_mark_threads called from threads in child
There should be no race in setting GC_markers_m1 value even in case of a client calls GC_start_mark_threads() from multiple threads in a child process. * include/gc/gc.h (GC_start_mark_threads): Add comment that the allocation lock is acquired internally. * mark.c [PARALLEL_MARK] (GC_wait_for_markers_init): Change assertion from I_DONT_HOLD_LOCK to I_HOLD_LOCK. * pthread_support.c [PARALLEL_MARK] (GC_start_mark_threads_inner): Likewise. * win32_threads.c [PARALLEL_MARK] (GC_start_mark_threads_inner): Likewise. * mark.c [PARALLEL_MARK] (GC_wait_for_markers_init): Remove LOCK/UNLOCK around GC_add_to_our_memory() call. * misc.c [PARALLEL_MARK && GC_ASSERTIONS && GC_ALWAYS_MULTITHREADED] (GC_init): Remove UNLOCK/LOCK around GC_start_mark_threads_inner call. * misc.c [THREADS && PARALLEL_MARK && CAN_HANDLE_FORK && !THREAD_SANITIZER] (GC_start_mark_threads): Wrap GC_start_mark_threads_inner() call into LOCK/UNLOCK.
Diffstat (limited to 'mark.c')
-rw-r--r--mark.c5
1 files changed, 1 insertions, 4 deletions
diff --git a/mark.c b/mark.c
index b005a1d2..53ca3e4a 100644
--- a/mark.c
+++ b/mark.c
@@ -924,7 +924,7 @@ GC_INNER void GC_wait_for_markers_init(void)
{
signed_word count;
- GC_ASSERT(I_DONT_HOLD_LOCK());
+ GC_ASSERT(I_HOLD_LOCK());
if (GC_markers_m1 == 0)
return;
@@ -937,15 +937,12 @@ GC_INNER void GC_wait_for_markers_init(void)
{
size_t bytes_to_get =
ROUNDUP_PAGESIZE_IF_MMAP(LOCAL_MARK_STACK_SIZE * sizeof(mse));
- DCL_LOCK_STATE;
GC_ASSERT(GC_page_size != 0);
GC_main_local_mark_stack = (mse *)GET_MEM(bytes_to_get);
if (NULL == GC_main_local_mark_stack)
ABORT("Insufficient memory for main local_mark_stack");
- LOCK();
GC_add_to_our_memory((ptr_t)GC_main_local_mark_stack, bytes_to_get);
- UNLOCK();
}
/* Reuse marker lock and builders count to synchronize */