views:

320

answers:

4

What is the best way to multi-thread in c language? Very efficient or not CPU hog. Thanks

+2  A: 

If you're on a UNIX-based platform (Linux or Mac OS X) your best option is POSIX threads. They're the standard cross-platform way to multithread in a POSIX environment. They can also be used in Windows, but there are probably better (more native) solutions for that platform.

Kyle Cronin
A: 

thanks! but im in windows platform.

sasayins
+1  A: 

Your question is a bit general to answer effectively. You might look into such things as:

CreateThread in the windows SDK

boost::thread

1800 INFORMATION
+3  A: 

The correct (standard) way to do this on C and Windows is with __beginthreadex.

This is usually preferred to calling CreateThread directly as CreateThread doesn't init C runtime support for the thread. So if you create a thread using CreateThread, and call a CRT function, bad stuff can/will happen.

Note that __beginthreadex calls CreateThread internally, but performs some other work behind the scenes.

James D