Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 315
CsTamas Avatar asked Mar 01 '23 12:03

CsTamas


1 Answers

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.

like image 59
Chris Arguin Avatar answered Mar 03 '23 01:03

Chris Arguin