Sexual specialization and inbreeding avoidance in the evolution of dioecy