Forum Discussion
Altera_Forum
Honored Contributor
13 years agoprintf thread safe ?
Dear all, I am using printf() in a task to display debug information in a Nios terminal window. However, I was wondering if printf() is thread safe. I am facing some buggy behaviour which I suspect t...
Altera_Forum
Honored Contributor
13 years agoI just checked it on my newly multi threaded program. The printf() function is not thread safe. Before you use printf(), lock the printing function and call fflush(stdout) before any printf() calls.int myPrint(char *str){MY_LOCK LOCK; fflush(stdout); printf("%s\n", str);}