Cosmic rays and thermal instability in self-regulating cooling flows of massive galaxy clusters