Solved

Multithreading required

Posted on 2003-11-27
4
463 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C dll call freezes 5 102
C language IDE – Compilers installation 14 71
Why is compiler in oracle server ? 9 66
How to learn Linux? 10 61
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…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.

810 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