Solved

Multithreading required

Posted on 2003-11-27
4
460 Views
Last Modified: 2010-08-05
Hi - I have to turn a fully functioning C API DLL into a multithreading DLL and I have checked the help files for both Borland and MSVS and am a bit confused by both of them as they seem so different - what I want to know is :

Which method(s) is effective in C code and will keep my code reasonably compatible with Microsoft and Borland

What I suspect is that I may have to make C++ wrappers around my code - which is OK if the code stays portable.

Can anyone help with the methods I shoudl use and maybe some examples.  I use a global structure and heaps of memory I want to share between threads - but there is searching, file IO and temporary states that must be kept separate between threads.  I am already using a Job Number which keeps things separate for different jobs that run on a single thread.

Thanks in advance

0
Comment
Question by:gmleeman
  • 2
  • 2
4 Comments
 
LVL 14

Accepted Solution

by:
Tommy Braas earned 250 total points
Comment Utility
Sounds like you need to incorporate the use of semaphores to protect your 'critical sections'. A semaphore will ensure that only one thread has access to a section of your code. You would be able to use sempahores to protect the areas in your code that has, primarily, write access to your shared memory. You might also want to look into the 'Readers Writers Problem' online. Depending on the level of exclusive access you want to your shared memory, you will have to approach the problem differently.

I would like to recommend the book "Concurrent Programming" by Burns and Davies, ISBN 0-201-54417-2

I would also suggest you have a look at the following document:

   http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/semaphore_objects.asp

0
 
LVL 3

Author Comment

by:gmleeman
Comment Utility
Thanks for your comments - will look at the site now...
0
 
LVL 3

Author Comment

by:gmleeman
Comment Utility
Will buy the book - too big a problem for expert exchange i feel.  Thanks
0
 
LVL 14

Expert Comment

by:Tommy Braas
Comment Utility
My pleasure!

Good luck!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements 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

6 Experts available now in Live!

Get 1:1 Help Now