Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Is parallel programming to do with threading.
I would like to learn about multi threading and wondering if parallel programming teaches me that?
Thanks
Posted

Google is your friend. This should get you started.

On MSDN [^]
 
Share this answer
 
It is related, but it is not exactly the same thing, specially if you think about the Task Parallel Library or Parallel Extensions.

Multi-threading means creating many threads, which can execute in parallel if multi-processors are available. The problem is that creating a new thread is a resource consuming task, so it is not good for fast operations.

If you are capable of creating, for example, only two threads that will run in parallel (each in its own cpu) then it is a real Parallel execution. Usually we don't know where the threads are executing and they can jump from one processor to another. Considering how time and resource intensive it is to create threads we should avoid doing it for very small tasks.

That's why there is the ThreadPool. There are threads there prepared to execute many small tasks (in parallel, if possible). We can always create our own threadpool, as the .Net ThreadPool has its own limitations.

Finally, there is the Parallel Extensions/Task Parallel Library. Internally it uses threads and the ThreadPool, but it is optimized to do many common things in parallel.
For example, if you have four CPUs, you can do a for over one million items, and it will try to use only 4 threads (one per cpu) to do the job. Surely it is much more complex than that, but the purpose is to be simple to use.
While using threads usually require Thread Synchronization, the TPL already has all the synchronization needed done, so your job is simple to pass it a collection to do something like a ForEach, and it will try to parallelize it.

Which one is better?
That depends. TPL is better for real independent things or a lot of small jobs. Threads can still be better if you want a dedicated thread for something.
 
Share this answer
 
We had to use multi-threading for something that looked like synchronously operations. This was the norm for programming, but things are changing and evolving and Microsoft has finally given us the ability to take advantage of multi-core processors on the systems we're programming for. Multithreaded programming is parallel, but parallel programming is not essentially multithreaded. Unless the multithreading happens on a single core, in which case it is only concurrent. Here parallel is truly simultaneous, while concurrent just looks as if it was simultaneous.

If you want to know in detail of Parallel Programming I would suggest you to read the Article[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900