Ask your own question, for FREE!
Computer Science 17 Online
OpenStudy (anonymous):

I want to create a multithreaded C program. It's going to go like this: Type in a sentence! >> // get a sentence from stdin until \n or EOF You took ${time} seconds. In the time it took you to enter that, I've added ${bignum} numbers! So yeah, this is probably the 'hello world' of multithreaded programming; how hard could it be? How do I do it in C?

OpenStudy (anonymous):

The language itself has no provision for threads; you'*ll have to use some kind of library. There are several options out there, depending on your OS. I heard good things about Qt, which is available on several platforms. Relying on user input for test programs can get tedious very quickly. Why not just write to stdout from two different threads? "Hello from thread A", "Hello from thread B", perhaps 100 times each?

OpenStudy (farmdawgnation):

Check out pthreads if you're on a linux machine. :)

OpenStudy (rsmith6559):

Chapter 4 of http://www.advancedlinuxprogramming.com/alp-folder/ was very helpful. Qt is a C++ system.

OpenStudy (anonymous):

I guess I'll take a peek at pthreads.h What's the alternative to pthreads on a windows machine? Thanks for the link btw; that page is begging me to hit it with wget :-D

OpenStudy (anonymous):

perhaps this? http://sourceware.org/pthreads-win32/ If you're fine using Windows-specific stuff, just use the Win(32) API, which offers threads: http://msdn.microsoft.com/en-us/library/windows/desktop/ms682516%28v=vs.85%29.aspx (there's also this book: http://www.amazon.com/Win32-Multithreaded-Programming-Aaron-Cohen/dp/B00007GW3Z/ref=sr_1_1?ie=UTF8&qid=1334965996&sr=8-1) There's nothing dramatically C++-specific in QThreads: http://doc.qt.nokia.com/main-snapshot/thread-basics.html Java has some language support for threads; QThreads were loosely based on the Java model. With the other libraries you may be working with a lower level of abstraction.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!