101
101

Reputation: 31

C programs synchronization

I am trying to use POSIX in windows and use semaphores for synchronization of C and C++ programs.Since we are talking for separate programs, is this even possible? Or semaphores are only for sync in C/C++ files of the same program?

Upvotes: 0

Views: 1163

Answers (3)

SystemFun
SystemFun

Reputation: 1072

For synchronization between seperate processes, a semaphore needs to be used.

See the following: Semaphores

Upvotes: 0

Seb
Seb

Reputation: 73

For communication between different programs, you need to use named semaphores. In POSIX Threads, the correct method to acquire a semaphore is : sem_open Just give a name to the semaphore, and use the same name in the programs which need to communicate.

See this answer for more details on how to do it: How to share semaphores between processes using shared memory

Upvotes: 1

Serge Ballesta
Serge Ballesta

Reputation: 149125

Semaphores are members in Inter Process Communication tools. They can natively be used in C or C++ to synchronize different programs.

Upvotes: 0

Related Questions