Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the gettimeofday function thread safe in Linux?

Tags:

c++

c

linux

The current time must be stored globally in order for gettimeofday to work, however I am not sure if the function modifies any global state so that concurrent execution is undefined.

like image 489
May Oakes Avatar asked Jul 10 '10 17:07

May Oakes


People also ask

Is time function thread safe?

The POSIX spec says time is required to be thread safe, and so it is.

Are function calls thread safe?

Functions named functionA() are never thread-safe.

What is thread safety in Linux?

Thread safety is a computer programming concept applicable to multi-threaded code. Thread-safe code only manipulates shared data structures in a manner that ensures that all threads behave properly and fulfill their design specifications without unintended interaction.

Are Linux sockets thread safe?

Sockets are not part of C++ Standard so it depends on implementation. Generally they are not thread safe since send is not an atomic operation.


1 Answers

gettimeofday is thread safe.

The (posix) functions listed here might not be, gettimeofday is not one of them.

like image 130
nos Avatar answered Sep 23 '22 06:09

nos