Is msgsnd() thread- and/or process-safe?

走远了吗. 提交于 2019-12-13 13:18:56

问题


What happens if two pthreads are calling the msgsnd() function at the "same" time, posting message to the same message queue ?

What if two processes do the same ? Does it matter if they are threads or processes ?

Specifically interested for Linux 2.6.15-2.5 #1 SMP PREEMPT Tue Sep 19 10:56:25 CDT 2006 x86_64 x86_64 x86_64 GNU/Linux


回答1:


The man page for pthreads tells you what you want to know:

A thread-safe function is one that can be safely (i.e., it will deliver the same results regardless of whether it is) called from multiple threads at the same time.

POSIX.1-2001 and POSIX.1-2008 require that all functions specified in the standard shall be thread-safe...

msgsnd is among the functions defined by POSIX, and is not excluded from this requirement. It doesn't matter if it is two threads or two processes.



来源:https://stackoverflow.com/questions/1158902/is-msgsnd-thread-and-or-process-safe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!