added unix implementation and option to run monitor in phread's context