use 'fputws_unlocked(S,F)' instead of 'fputws(S,F)'