Inserted machinery for resizing the hive (number of worked threads) by putting bees to sleep using a semaphore.
For this we need two things.
- We need to keep track of the amount of bees that actually need to be awake (
hive->num_awake_bees
) - Each bee needs a semaphore (
hive->sem_bees[i]
) for blocking that worker thread in the case that it is asleep.
Any sleeping bees are then blocked by this semaphore in the threadServeLoop
.
Only when the hive is resized are the semaphores of any awakened bees unlocked.
The logic for actually choosing a new thread-count is not yet ready to be merged.
However to keep our MRs small and separated we can already consider merging this machinery in.
Currently, nothing actually happens.
In future, resizing the hive would be done in SAC_MT_PTH_do_spmd_execute
in mt_pth.h
.
P.S.
I have no idea why findQueenClass
and mark
are needed, and what they do.
They have been copied from Stuarts dynamic adaptation code in https://gitlab.sac-home.org/stg/sac2c/-/blob/stuart-mtdynamic/src/libsac/mt_beehive/mt_beehive.c.
Without it, the code will not work.