variable
variable

Reputation: 9634

Does C# have the concept of multiprocessing (in addition to multithreading)?

I come from python programming background. In python the interpreter runs in a process. Multi threading is recommended for IO operations (file io, http request, etc) where as multi processing is recommended for CPU intensive operations (calculations).

Multi threading means within the processes multiple threads are created. Multi processing means a new process (interpreter) is created for each task.

I understand that C# also has the concept of async/await, Task.Run and Task Parallel library. It appears that these all multi threading (that is - threads running in the same process). So C# does not have multi processing? What is the concept/approach for IO vs CPU bound work in C#?

Upvotes: 6

Views: 3814

Answers (1)

bazza
bazza

Reputation: 8394

Both languages are Turing complete, so in principle whatever can be done in one can also be done in the other!

A less trite answer is that, no, typically one does not resort to multiprocessing in C#. Multiprocessing in Python was added because of the global interpretter lock; instead of ridding the interpretter of that lock and facilitating proper multi-threading within a single Python process, it was easier (at the time - Python was a much smaller community at that time, fewer volunteers, etc; important considerations) to implement multiprocessing and get something close to the same sort of result with less work required. The end result is, so far as I'm concerned, actually quite good, being a lot closer to the Actor model than one classically gets with just threads. [I say "close" because, in Actor model one would normally consider the other Actor to already be there, not something you start up dynamically.]

C# also has a run time interpreter (JIT compiler) but this has no construct like the Global Interpreter Lock. So it's possible for this runtime to use operating system threads for C# threads. So it has no built-in Actor model style Multi Processing classes / library, but you could write your own. Like a lot of other languages of this ilk, it has a thread pool which gets used for some operations.

The .NET C# Task Parallel library (and its DataFlow library) can do Actor model, so it will "feel" a lot like Python's multiprocessing, but it's not spawning up separate processes to do so.

Upvotes: 4

Related Questions