multithreading - thread safe containers in arrays -


Can anyone please explain, even if there is access to the array with multi-thread, where each thread has a different element of the array Working on

So there are n elements, and n threads ==> nth thread is working on the nth element of the array?

Is anyone enough to explain what it is safe or not? And why not?

Thanks p.s. Main language C # or Java, are interested in Python, but I would prefer any other input from esoteric language experts.

In most languages, it will be safe (provided that you are only using a specific array element within a thread at a time) - however, this is not a good idea.

The main problem is sharing one of the false. By writing items on the array from many threads, you will get very poor performance, because you are constantly swapping the cache lines, it is a particularly bad idea in the managed languages ​​like C # and Java. For example, in C #, check on the CLR array Has been doing. This causes any array to reach a variable (length) stored just before the first element of the array, which causes the continuous cache. This was done by a great demonstration of this - you can see that parallel performance is slowly slowing down slowly due to its issue gradually.

This is better for pushing work into threads as separate data variables, and after the fact "Write" your array.


Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -