Halogenated polymers with high thermal stability and flame-resistance