Bag Dev
Bag Dev

Reputation: 185

multiple processes read/write fifo

I need to write a multiple processes that write to FIFO, I'm wondering how to sync among them, do I need to write some lock, if yes then would that be slow as a process has to wait for the other to free the lock? please let me know what other best way to achieve interprocess communication?

Upvotes: 1

Views: 1991

Answers (1)

NickO
NickO

Reputation: 741

"do I need to write some lock"

Well, probably yes. If you are working with shared memory (pthreads, openmp) then you need to have some sort of read-write lock to prevent race conditions, data invalidation, etc. If you are working with distributed memory then you'll want to think about some kind of reduction operation to get all of the data in one place.

"if yes then would that be slow as a process has to wait for the other to free the lock?"

That is up to you, the programmer. It's easy to write slow, inefficient programs but will take some time to thing of ways to increase the program execution, speed, etc. I might also add that where you think the performance bottlenecks should be aren't always where they actually occur. It's a good idea to become best friends with a debugger and performance analyzer.

Here are some resources to get you started, I recommend doing research, writing code, and asking specific questions to get better help.

https://computing.llnl.gov/tutorials/pthreads/

https://computing.llnl.gov/tutorials/openMP/

https://computing.llnl.gov/tutorials/mpi/

Also check out the 'related' questions to the right for some other great resources.

Upvotes: 2

Related Questions