Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Multithreading required

Posted on 2003-11-27
4
Medium Priority
?
471 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 1000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand opening and reading files 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.
Suggested Courses

564 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