PDNS thread architecture

Make PDNS threading architecture more robust. If any unexpected exceptions happen take the decisive action.