Fix race condition when updating expression flags: max_shared and closed

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>