Solved

Message Queue processing without a  Mutex (C)

Posted on 2010-08-18
5
532 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 500 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A short article about a problem I had getting the GPS LocationListener working.
In this post we will learn different types of Android Layout and some basics of an Android App.
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
This video is in connection to the article "The case of a missing mobile phone (https://www.experts-exchange.com/articles/28474/The-Case-of-a-Missing-Mobile-Phone.html)". It will help one to understand clearly the steps to track a lost android phone.

635 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