Solved

Multithreading required

Posted on 2003-11-27
4
464 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
ID: 9835462
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
ID: 9844968
Thanks for your comments - will look at the site now...
0
 
LVL 3

Author Comment

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

Expert Comment

by:Tommy Braas
ID: 9908852
My pleasure!

Good luck!
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Read file descriptor 3 in C 14 113
Arduino EDI - Programming language 3 104
Super Scope, DHCP 5 91
How to access ANSI/IEEE Std 754 or equivalent information ? 3 73
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…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

828 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