Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sharing mutexes between modules

Tags:

c

mutex

How does one use mutexes between modules?

I have a module that creates threads that run functions from another module.

I need to read a variable in the thread creating module and the threads that execute functions from other #included modules modify the variable. How does locking and unlocking of the mutexes occur in a system like this?

e.g. Logic module spawns 2 threads, each run a function from another module. There is a variable called current position that needs to be read from the logic module if e.g. another module calls getCurrentPosition. How do these threaded functions that are existing outside of the logic module use the mutexes defined in the logic module?

The thread running functions need to lock and unlock the mutex that is defined in the logic module.

like image 618
some_id Avatar asked Jul 15 '26 18:07

some_id


1 Answers

You can use mutex just like you declare and use extern variable "current position". No big difference here.

extern pthread_mutex_t mtx;
extern int current_position;
like image 185
blaze Avatar answered Jul 18 '26 08:07

blaze