B
B
BadCats2016-08-13 17:26:40
C++ / C#
BadCats, 2016-08-13 17:26:40

Work of static method in multithreading?

Hello everyone, I started to study flows. The author of the course I'm taking gave an example of working with static methods in multithreading - where he noticed that at least usually there is only one static method - because it belongs to the entire object. But at the same time, when working with threads, when this method is executed in both threads, for example, primary and secondary, for each thread, a "copy" of the static method for each thread is created, as it were; while the author notes the word "copy" is used for simplified understanding in this training material, after which. - I quote. - "In fact, there are very tricky processes" such as - local storage of the thread with the preservation of intermediate calculations of registers - because REALLY THE STATIC METHOD IS ALL THE SAME, but thanks to these complex processes and mechanisms, we have the illusion that the static method is copied. ... But we, as high-level programmers, are not interested.'"
Who can explain to me what these mechanisms are and how they are used to achieve such a goal as creating the illusion of a copy of a static method, and what does the terms given by the author have to do with it: a stream storage with saving intermediate register calculations and what do they MEAN?
I forgot to say that If the author was still wrong, I would like to give a definition of concepts. Given in the quote, and yet this quote and what the author wanted to say, there is some kind of relationship and the quote will serve as a hint. Thanks in advance!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
Ogoun Er, 2016-08-15
@BadCats

In .NET, shared resources are data, not methods. Those. everything that is in the body of the method and the method itself can be processed in parallel in any number of threads independently of each other, but for example, the field of a static class will already be visible to several threads at once and access to it must be made thread-safe.
Regarding your question, in general, there is no difference whether a method is static or not, any method can be launched for parallel execution in different threads. It is only important to follow how these methods will work with shared resources.

P
Peter, 2016-08-13
@petermzg

Here are the courses. Blizzard. Neither normal class methods nor static ones are copied.
Perhaps the stack that the system creates for each thread was meant, but the stack is not a copy either.
Instead of courses, it's better to read Richter's book "windows for professionals"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question