copy from  http://swtch.com/libtask/, add some comment