After cancelling a thread (unless it's detached, but mining threads aren't), it is always necessary to join the thread so the system will release resources.
This also simplifies kill_mining a bit.
Add log-file option to automatically redirect stderr to a file
From bfgminer https://github.com/luke-jr/bfgminer/commit/b0240dd004823cb1834b21508e4b621e9e7574cf
Added missing permission flags to Windows build #333
sshare could have already been free'd by parse_stratum_response in stratum_rthread by the point we reach this code - possible segfault fixed
immediately exit threads if doing hard reset
Hard reset only when gpu-threads or devices are changed, but not when algorithm is changed.
Also a little refactor.