Does the message queue support multithreading?

I have 3 questions about the relationship of threads and processes.

  • Can the Linux function msgget (), msgsnd () and msgrcv () be called by multiple threads in the same process? These functions in different threads should try to access the message queue (r / w) for one process. Is it supposed that all race conditions should be taken into account by the system? If not, is there a good way to support threads and send a message to its main thread (process)?

  • Is it possible to use the semop () function to synchronize threads in one process?

  • There is a shared memory that has the following objects for access.

    • process
    • multiple threads in one process. Should I use the interprocess level semaphore and the thread level semaphore at the same time ? Any easy way to handle this?

A lot of questions. :) thanks.

+4
source share
1 answer

Can the Linux function msgget (), msgsnd () and msgrcv () be called by multiple threads in the same process?

You do not need to worry about the racing conditions, the system will take care of it, with these challenges there will be no race condition.

Can the semop () function be used to synchronize threads in a single process?

Yes, read more in the documentation.

Should I use a level semaphore between processes and a thread level semaphore?

Any resource that is globally distributed between threads or processes depends on race conditions due to one or more threads or processes trying to access it at the same time. Therefore, you need to synchronize access to such a global global resource.

+3
source

Source: https://habr.com/ru/post/1400335/


All Articles