Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Message Queue processing without a  Mutex (C)

Posted on 2010-08-18
5
Medium Priority
?
540 Views
Last Modified: 2012-05-10
Hi,

I'm trying to dream up a clever way to create a Message Queue processing system with multiple threads without the use of a mutex for maximum performance. Since I'm working in C, the Message Queue could be a linked pointer list. Multiple threads would be adding to the Message Queue (adding to the linked pointer list). Only one thread would be processing Messages and removing them from the queue in FIFO order.

Guess the problem I see is if an input and the processor thread both try to modify the first message in the list. Is there a good way to do this without a mutex or is a mutex the way to go?
0
Comment
Question by:php-newbie
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 2000 total points
ID: 33465721
>>Is there a good way to do this without a mutex or is a mutex the way to go?

No. That's what mutexes were created for. There are some workaround techniques like using a variable as a lock, but I would not recommend using that.

BTW, if you were on Windows, one way to reduce the performance footprint would be to use a CRITICAL_SECTION (http://msdn.microsoft.com/en-us/library/ms682530(VS.85).aspx) instead of a Mutex object.
0
 
LVL 8

Expert Comment

by:Anthony2000
ID: 33466092
Curious, jkr, if on Windows, would you not use the MessageQueue api? (I am not sure if it is thread safe?). Unless this is an exercise to create your own?
0
 
LVL 86

Expert Comment

by:jkr
ID: 33466239
Sure, but that API is to manage a whole different beast - IMO that would be overkill for a simple message queue...
0
 

Author Comment

by:php-newbie
ID: 33466345
Ahhh, we're on Win, Linux, Android and I need a common implementation across all platforms. Thanks!
0
 
LVL 86

Expert Comment

by:jkr
ID: 33466431
For a common implementation, check out the 'pthreads' library, it's available on almost all platforms and of course has mutexes.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If your app took Google’s lash recently, here are the 5 most likely reasons.
You should read OS supplied guidelines before developing. I can't stress that enough. The guidelines will help you understand the reasons mobile app developers do what they do.  Apple is very particular when they review appstore submissions.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question