GSoC 2026 : POSIX Message Queue thread release order is not priority based (#3791)

Hi everyone,

I’m interested in the “Message Queue Improvements and Fixes” GSoC project and have been investigating one of the linked issues: POSIX Message Queue thread release order is not priority based(#3791). I’m using RTEMS 7 with the erc32-sis BSP.

Initial Problem
According to the POSIX specification, when multiple threads are waiting to receive a message on a message queue and a message arrives, the thread of highest priority that has been waiting the longest should be selected. However, in my initial tests I observed FIFO behavior (low priority thread woken first) even though I assumed the queue was configured correctly.

Modification Made
After reviewing the code, I found that in cpukit/posix/src/mqueueopen.c, inside the function _POSIX_Message_queue_Create(), the core message queue discipline was set to CORE_MESSAGE_QUEUE_DISCIPLINES_FIFO. I changed it to CORE_MESSAGE_QUEUE_DISCIPLINES_PRIORITY. This ensures that the underlying core message queue uses priority-based thread waiting queues.

Verification
To verify the effect, I wrote a test program (posix_mq_priority_wakeup_test .txt (6.4 KB)
) that:

  • Creates a POSIX message queue with default attributes.
  • Creates two threads: one with POSIX priority 20 and one with POSIX priority 10.
  • Uses two independent binary semaphores to control the order in which the threads enter mq_receive() (the lower priority thread blocks first, then the higher priority thread blocks later).
  • Sends a single message and records which thread receives it.
    After applying the fix, the test output shows correct behavior:

Release low priority thread
Thread POSIX prio 10: RTEMS prio 245, blocking on mq_receive()…
Release high priority thread
Thread POSIX prio 20: RTEMS prio 235, blocking on mq_receive()…
Before sending: msgs=0
Send first message: Hello
Thread prio 20: received message: Hello
PASS: High priority thread received first message (priority order)

Conclusion
The issue is resolved by this one-line change. I believe this fix should be merged to ensure POSIX compliance. I would be happy to provide a proper patch and update the issue status.

@gedare @JoelSherrill Looking forward to any feedback. Thank you!

What’s the test output without your fix?

Hi, @gedare
Without my fix the test output is:

=== POSIX Message Queue Priority Wakeup Test (Modified) ===
=== Test includes second mq_send verification ===
Release low priority thread
Thread POSIX prio 10: RTEMS prio 245, blocking on mq_receive()…
Release high priority thread
Thread POSIX prio 20: RTEMS prio 235, blocking on mq_receive()…
Before sending: msgs=0
Send first message: Hello
Thread prio 10: received message: Hello
FAIL: Low priority thread received first message (FIFO order)
Send second message: World
Second mq_send succeeded immediately
After sending: msgs=0
Thread prio 20: received message: World
=== Test Finished ===

As shown, the low-priority thread (POSIX 10) receives the first message, confirming the FIFO behavior. After applying the fix (changing to CORE_MESSAGE_QUEUE_DISCIPLINES_PRIORITY), the high-priority thread (POSIX 20) correctly receives the first message, as I reported earlier.

Please let me know if you need any further details.

Hi everyone, I have been continuing to work on Issue #3791 and exploring possible solutions.

Based on the investigation and earlier discussion in this thread, I prepared a draft GSoC proposal for the “Message Queue Improvements and Fixes” project, focusing on the POSIX message queue wakeup policy.

The proposal suggests introducing an optional priority-based wakeup policy (mq_ispriority_np) while preserving the existing FIFO behavior as the default.

I would really appreciate any feedback on the design or scope before submitting the final proposal.

Draft proposal: GSoC Proposal

Thank you for your time and guidance.

Make sure your proposal is linked from your tracking page in gitlab.

Hi @gedare, thank you for the reminder! I have already added the link of my draft proposal to the tracking page. A new merge request (MR #240) from the correct branch has been created to update the file tracking/2026/xinhong_hu.md. You can review the change there.