cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
General C++ Programming
Threads, mutex and multiple functions
Threads, mutex and multiple functions
Mar 9, 2020 at 7:20am UTC
zongul
(8)
I have two functions, lets call func1 and func2, two threads start_t1 and start_t2 and one mutex.
I want that the two functions run parallel and my question would be if I need to declare mutex for all used functions so 2 in my case or is one enough?
Mar 9, 2020 at 9:07am UTC
coder777
(8444)
You need a mutex for most of the shared resource. This resource is usually a variable.
For a simple type variable (such as bool) there might not be a mutex needed if and only if it is write only in one thread and read only in all other.
So a mutex is attached to variable not a function.
Topic archived. No new replies allowed.