Solved

Message Queue processing without a  Mutex (C)

Posted on 2010-08-18
5
515 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
  • 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Introduction This article is a continuation of Part-1 as evident from the title. Please visit this page (http://www.experts-exchange.com/articles/18706/Backing-up-personal-data-on-your-Android-device-Part-1.html) to read the earlier Part -1. If y…
This is an explanation of a simple data model to help parse a JSON feed
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

762 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now