Could anyone please give a sample or any link that describes how to spawn thread where each will do different work at the same time.
Suppose I have job1 and job2. I want to run both the jobs simultaneously. I need those jobs to get executed in parallel. how can I do that?
Thread functions in C/C++ In a Unix/Linux operating system, the C/C++ languages provide the POSIX thread(pthread) standard API(Application program Interface) for all thread related functions. It allows us to create multiple threads for concurrent process flow.
Threads/ Processes are the mechanism by which you can run multiple code segments at a time, threads appear to run concurrently; the kernel schedules them asynchronously, interrupting each thread from time to time to give others chance to execute.
the standard C printf() and scanf() functions use stdio so they are thread-safe.
I was recently reading "The C Programming language" by Ritchie, I noticed that C is a single threaded language.
Well, fundamentally it's as simple as:
ThreadStart work = NameOfMethodToCall;
Thread thread = new Thread(work);
thread.Start();
...
private void NameOfMethodToCall()
{
// This will be executed on another thread
}
However, there are other options such as the thread pool or (in .NET 4) using Parallel Extensions.
I have a threading tutorial which is rather old, and Joe Alabahari has one too.
Threading Tutorial from MSDN!
http://msdn.microsoft.com/en-us/library/aa645740(VS.71).aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With