007 Thread Risk

I. Overview

Multithreading can help us achieve concurrency, but concurrency will bring some problems.

[1] Thread safety issues

[2] Active Issues

[3] Performance issues


 

2. Activity issues

Common activity problems include:

[1] Deadlock:

  The classic deadlock problem has the philosopher's problem. When a deadlock occurs, the program cannot continue to run.

    The main reasons for deadlock problems are:

        Only get some resources, but will not give up the current resources.

[2] Hunger

  Due to thread priority issues, some threads may not run once for a long time.

    Classic problem: high-priority threads occupy time slices for a long time, and other low-priority threads are starved to death.

[3] Livelock

  Classic question:

    The two threads yield resources to each other, but they acquire other resources after they have not given up resources.

      For example, the issue of giving way.

    Livelocks are much more harmful than deadlocks and are not easy to detect.

Deadlock Detection:

  We can use tools to detect deadlocks, but starvation and livelocks are hard to detect.


 

3. Performance issues

  The root of multi-threaded concurrency is that time slices are switching, but the switching of time slices takes time.

    When it takes more time to switch the time slice, the resources originally given to the normal operation of the program are switched by the time slice

      If you use it, then there will be performance problems.

  The core of the performance problem is:

    Determine if concurrency is required, how much concurrency is required, and how much concurrency will take.


 

4. Safety issues

  When multi-threaded execution, there will be resource contention problems, if not properly controlled, then there will be erroneous results.

    This is the thread safety issue.

  Resolution of security issues:

      Use thread synchronization to solve that problem.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325206113&siteId=291194637