007 Thread Risk

Source: Internet
Author: User

One. Overview

Multithreading can help us achieve concurrency, but concurrency poses some problems.

[1] Thread safety issues

[2] Active issues

[3] Performance issues

Two. The problem of activity

Common activity issues are:

[1] Deadlock:

The classic deadlock problem has a philosopher's problem, and when a deadlock occurs, the program cannot continue running.

The main cause of the deadlock problem is:

Only partial resources are obtained, but the current resource is not discarded.

[2] Hunger

Because of a thread priority issue. Some threads may not run for a long time.

Classic problem: High-priority threads consume time slices for a long time, and other low-priority threads are starved.

[3] Live Lock

The classic question:

Two threads mutually humble resources, but have not abandoned the resources after the acquisition of other resources.

such as giving way to the problem.

A live lock is much more dangerous than a deadlock, and it is not easy to detect.

Deadlock Detection:

We can use tools to detect deadlocks, but it's hard to detect hunger and live locks.

Three. Performance issues

Multi-threaded concurrency is the root of the time slice in the switch, but the time slice of the switch takes time.

When switching time slices takes more time, the resources that were originally given to the program are switched by time slices.

Use, then there is a problem with performance.

The core of the performance problem is:

Determine if concurrency, how much concurrency, and the amount of concurrent time are required.

Four. Security issues

When multithreaded execution, there will be contention for resources, if the control is not appropriate, then there will be incorrect results.

This is a thread-safety issue.

Solutions to security issues:

Use thread synchronization to resolve the issue.

007 Thread Risk

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.