Skip to content

Commit

Permalink
Add logging to help with CI deadlock.
Browse files Browse the repository at this point in the history
  • Loading branch information
mjp41 committed Jan 29, 2025
1 parent 846f349 commit 92287a8
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/test/func/protect_fork/protect_fork.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,36 +27,46 @@ int main()

size_t N = 3;

snmalloc::message<1024>("Testing PreventFork");

snmalloc::message<1024>("Adding alternative calls to pthread_atfork");
pthread_atfork(simulate_allocation, simulate_allocation, simulate_allocation);

snmalloc::message<1024>("Initialising PreventFork singleton");
{
// Cause initialisation of the PreventFork singleton to call pthread_atfork.
snmalloc::PreventFork pf;
}

snmalloc::message<1024>("Adding alternative calls to pthread_atfork");
pthread_atfork(simulate_allocation, simulate_allocation, simulate_allocation);

snmalloc::message<1024>("Creating other threads");
for (size_t i = 0; i < N; i++)
{
std::thread t([&block, &forking]() {
std::thread t([&block, &forking, i]() {
{
snmalloc::PreventFork pf;
snmalloc::message<1024>("Thread {} blocking fork", i);
block++;
std::this_thread::sleep_for(std::chrono::milliseconds(100));
while (!forking)
std::this_thread::yield();
std::this_thread::sleep_for(std::chrono::milliseconds(100));

snmalloc::message<1024>("Thread {} releasing block", i);
block--;
}
});

t.detach();
}

snmalloc::message<1024>("Waiting for all threads to block fork");
while (block != N)
std::this_thread::yield();

snmalloc::message<1024>("Forking");
forking = true;

fork();

if (block)
Expand Down

0 comments on commit 92287a8

Please sign in to comment.