getchar_unlocked

How can we use getchar_unlocked() for string inputs in C/C++?

1 Like

getchar_unlocked() acts exactly like getchar() except it’s not thread safe. Meaning more than one thread can’t acess it without synchronization (and this is the point where i realize i’m failing my oop exam in two days).

Anyways to answer your question use it exactly like getchar() it doesn’t cause any problems in any online judges i’ve used.

http://www.cplusplus.com/reference/cstdio/getchar/

In the above example replace getchar() with getchar_unlocked(). Reason why people use it is because it doesn’t check for thread safety therefore theoretically it should be faster than getchar() (even though i personally didn’t see this effect).

2 Likes

de si draganče

Ω Ω Ω Java Ω Ω Ω

//