https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121429
--- Comment #7 from Jerry DeLisle <jvdelisle at gcc dot gnu.org> ---
(In reply to Andre Vehreschild from comment #6)
> Well, I suppose something like:
>
> diff --git a/libgfortran/caf/shmem.c b/libgfortran/caf/shmem.c
> index 446e5f54483..24400672336 100644
> --- a/libgfortran/caf/shmem.c
> +++ b/libgfortran/caf/shmem.c
> @@ -463,6 +463,7 @@ _gfortran_caf_deregister (caf_token_t *token,
> caf_deregister_t type, int *stat,
> free (ca);
> free (TOKEN (*token));
> *token = NULL;
> + sync_team (caf_current_team);
> }
> else
> {
>
> should do the trick.
Indeed, this fixes it. I will keep this on my test branch and push out to the
devel/gfortran-test branch.