Is it thread safe for strcmp?

strcmp(variable, "constant");

Or do I need to protect it with a mutex?

+3
source share
5 answers

If a variable can be modified by another thread, you must protect it. No magic here - higher-level languages ​​can perform such a function call atomically, and this is β€œmagic” not present in C.

, ( ) "variable" ( ), ( : ). strcmp, .

+4

, .

strcmp , variable, , "" , , , .

+2

, .
, strcmp, ( ), strcmp 2 .
, variable , strcmp , strcmp , variable.

+1

. , , .

0

Have a look here: http://www.opengroup.org/onlinepubs/009695399/functions/xsh_chap02_09.html

POSIX has a list of unsafe functions. Accordingly, at least on POSIX it strcmp()will be thread safe.

0
source

Source: https://habr.com/ru/post/1778699/


All Articles