Fix generic mutex usage, see https://svn.boost.org/trac/boost/ticket/9461.
Add checks for invalid UTF-8 sequences, see: https://svn.boost.org/trac/boost/ticket/9473