What is a thread discussion?

Can someone explain if this is just a question?

I have googled, but I can not find a simple explanation.

+68
language-agnostic multithreading
Dec 28 '09 at 16:46
source share
10 answers

Essentially, thread conflict is a condition where one thread is waiting for a lock / object that is currently held by another thread. Therefore, this waiting thread cannot use this object until another thread unlocks this particular object.

+53
Dec 28 '09 at 16:50
source share

A few answers seem to focus on lock conflict, but locks are not the only resources on which the conflict may arise. A conflict is simple when two threads are trying to access the same resource or related resources in such a way that at least one of the competing threads is slower than if the other threads were not running.

The most obvious example of competition is blocking. If thread A has a lock and thread B wants to get the same lock, thread B will have to wait until thread A releases the lock.

Now it depends on the platform, but the thread may experience slowdown, even if it does not need to wait until another thread releases the lock! This is because locking protects some data, and the data itself will often be discussed.

For example, consider a thread that receives a lock, modifies an object, then releases the lock and performs some other actions. If two threads do this, even if they never fight for blocking, threads can run much slower than if only one thread was running.

Why? Let's say that each thread runs on its own core on a modern x86 processor, and the kernels do not have L2 cache. Only one thread can an object remain in L2 cache most of the time. When both threads execute, each time one thread modifies an object, the other thread will detect that the data is not in its L2 cache, because the other CPU has invalidated the cache line. For example, on Pentium D, this will cause the code to work at FSB speed, which is much less than the L2 cache speed.

Since a conflict can occur even if the lock itself is not considered, a conflict can also occur when there is no lock. For example, let's say your processor supports the atomic increment of a 32-bit variable. If one thread continues to increase and decrease the variable, the variable will be a lot of time in the cache. If two threads do this, their caches will struggle to own the memory holding this variable, and many accesses will be slower because the cache coherence protocol works to protect every basic ownership of the cache line.

Oddly enough, locks usually reduce competition. What for? Since without blocking two threads can work on the same object or in a collection and cause a lot of conflicts (for example, there are free queues). Locks will tend to dash out competing threads, allowing instead to run consistent threads. If thread A contains a lock and thread B wants the same lock, the implementation can instead execute thread C. If thread C does not need this lock, then in the future the rivalry between threads A and B can be avoided for some time. (Of course, it is assumed that there are other threads that can run. This will not help if the only way the system as a whole can make it useful is to start threads that are competing.)

+119
Aug 15 2018-11-11T00:
source share

From here :

Conflict occurs when a thread is waiting for a resource that is not readily available; it slows down the execution of your code, but can clear over time.

A deadlock occurs when a thread is waiting for a resource, that the second thread is blocked, and the second thread is waiting for a resource that the first thread is blocked. More than two threads can be involved in a dead end. Deadlock never solves itself. This often leads to an application or part that is experiencing a dead end to stop.

+16
Dec 28 '09 at 16:50
source share

You have 2 threads. Thread A and Thread B, you also have object C.

A is currently accessing object C and has placed a lock on this object. B must access object C, but cannot do so until A releases the lock on object C.

+2
Dec 28 '09 at 16:50
source share

I think that against the background of the question there should be some clarification from the OP - I can come up with 2 answers (although I'm sure there are additions to this list):

  • if you mean the general "concept" of discussing threads and how it might be present in the application, I postpone the detailed answer by @DavidSchwartz above.

  • There is also a .NET CLR Locks and Threads: Total # of Contentions performance counter. As taken from the PerfMon description for this counter, it is defined as:

    This counter displays the total number of times that threads in the CLR attempted to obtain a managed lock without success. Managed locks can be acquired in a variety of ways; the lock statement in C # or by calling System.Monitor.Enter or using MethodImplOptions.Synchronized custom attribute.

... and I'm sure others are for other OS and application frameworks.

+2
Sep 05 '14 at 21:00
source share

Another word could be concurrency. It is simply the idea of ​​two or more threads trying to use the same resource.

+1
Dec 28 '09 at 16:50
source share

I believe that there is competition between two or more threads over a common resource. The resource can be a lock, counter, etc. Competition means "who is his first." The more threads, the more disputes. More frequent access to the resource causes more controversy.

+1
May 21 '12 at 9:57 a.m.
source share

A thread conflict also affects I / O operations. An example where a thread waiting to read a file can be considered a conflict. Use I / O completion ports as a solution.

0
Mar 22 '16 at 13:18
source share

A lock conflict occurs when a thread tries to obtain a lock for an object that is already received by another thread *. While the object, the thread is blocked (in other words, it is in the Wait state). In some cases, this can lead to the so-called serial, which negatively affects the application.

from dotTrace documentation

0
May 24 '16 at 14:12
source share

Imagine the following scenario. You are getting ready to study tomorrow and feel a little hungry. So, you give your little brother ten bucks and ask him to buy pizza for you. In this case, you are the main thread and your brother is the daughter thread. As soon as your order is considering that you and your brother are doing their job at the same time (i.e. studying and buying pizza). Now we have two cases: to consider. First, your brother returns your pizza and completes while you study. In this case, you can stop studying and enjoy pizza. Secondly, you will finish your study and sleep early (i.e. your assigned job for today - studying for tomorrow's final exam - is done) before pizza is available. Of course you cannot sleep; otherwise, you will not have a chance to eat pizza. What you are going to do is wait until your brother returns the pizza.

As in the example, two cases give a sense of rivalry.

0
May 12 '17 at 13:55
source share



All Articles