Multithreaded programming question

Started by
5 comments, last by Russell 22 years, 4 months ago
I want to add multithreaded programming to my program, but I''ve heard it can get a little messy if you don''t know what you''re doing. So I was wondering if there are any good online resources (of course there are some out there, but I specified "good" ones ), or if a book would better cover this topic. I''ve seen ORielly''s Win32 Multithreaded Programming book at my local bookstore, but I''m sure there are some others. And BTW, I''m looking to do this on Win32. Any help would be greatly appreciated. Thanks. Russell
Advertisement
There''s a couple of articles on this site, thought it may take some digging to find them. Also, this is a fairly common question so search the forum. There''s a thread running now about some issues involved when doing this.

Magmai Kai Holmlor

"Oh, like you''ve never written buggy code" - Lee

"What I see is a system that _could do anything - but currently does nothing !" - Anonymous CEO
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
You should look for the pthread library. Its a Posix thread library, that works for Win32 too. I donot if there are other or better ways for multithreading in Win32.
Jeff Richter''s "Advanced Windows" book also has a fairly comprehensive take on Win32 threads among other things.

Here''s the URL to pthreads for Win32 http://sources.redhat.com/pthreads-win32/




‘But truth's a menace, science a public danger.’ Brave New World, Aldous Huxley
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
Forgive me if im wrong but i dont think you said what language you are using. If you use <a href="http://www.inprise.com"> Delphi Pascal</a> (I have version 4), there is excellent support for multithreading
One tipp: don''t forget Mutexes (or Semophores (? not sure about the second name :o)).... you''ll find out what they''re about later... but just don''t forget them (My first multithreaded server was written without mutexes/threadsafety, and I kept on wondering why it was crashing :p)..

ok,
good luck!
cya,
Phil


Visit Rarebyte!
and no!, there are NO kangaroos in Austria (I got this questions a few times over in the states )
Visit Rarebyte! and no!, there are NO kangaroos in Austria (I got this question a few times over in the states ;) )
If you aren''t worried about portability then just use the straight Win32 APIs for threading (don''t use pthreads).

Threading is easy, if you know what you are doing. Getting to the point where you know what you are doing can be tricky.

Like phueppl1 said, Mutexes, Semaphores, Events and Critical Sections are your friend. You absolutely must protect shared data from being accessed by more than one thread at a time*.


*=in general. If you design your app correctly, then you can get around this requirement.. but it will make your app much more complex. Stick to the basics for now.

Also, I''ve said this on another thread, but if you are using any C runtime (CRT) functions in your thread, then use _beginthreadex() to start the thread instead of CreateThread(). C runtime functions are stuff like printf, sprintf, fopen, etc. _beginthreadex() initializes some CRT stuff for your new thread (like a thread-local copy of errno, for instance).


-Brannon
-Brannon

This topic is closed to new replies.

Advertisement