开发者

Should I use msgsnd or mq_send?

I'm learning Unix IPC, and my book only talks about the msg* family of functions. However while browsing the man pages I learned about the mq_ equivalents. http://techpubs.sgi.com/library/tpl/cgi-bin/getdoc.cgi/0650/bks/SGI_Developer/books/T_IRIX_Prog/sgi_html/ch06.html describes some differences between th开发者_开发问答e two, but I'm not sure how much of that is implementation-specific. Are there any compelling reasons to use one family over the other? Is either one "better" than the other?


The mq_* functions are the POSIX functions. The msg* functions are from what is generally known as 'System V IPC' (because they are part of the IPC facility introduced with UNIX System V that included shared memory and semaphores too). I think it is fair to say that the msg* functions are included in the POSIX and X/Open standard more because of backwards compatibility than for being otherwise desirable; that may be doing them an injustice, but normally standards try to avoid multiple ways of achieving the same result. They were neither of them in the original versions of POSIX.

You need to consider where you will port your code. I'd would suggest using the more modern mq_* functions if they are available everywhere you need to go - though I haven't used them myself. Generally speaking, the msg* functions were less frequently used than the shared memory and semaphore functions, but that interface has been around (a decade or more) longer than the POSIX one, so it might be more widely available.


Generally you should try to use the POSIX versions when you can as they should be more portable to a wider range of platforms.

The major differences are that POSIX queues can generate a signal or spawn a new thread when messages are put onto an empty queue. POSIX queues also always return the oldest message of the highest priority; the SysV queues can return a message of any priority you specify.

Everyone's mileage will vary but I find the POSIX interface to be more intuitive and less quirky than SYSV, or SysV IPC in general.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜