Yards farm charging station--process and thread

Source: Internet
Author: User

Yards farm charging station--process and thread

A process is a container, not an execution entity, and a thread is an executing entity.

The process consists of two parts,

1, the kernel object, the essence is a data structure, by the operating system management

2, DLLs and actuators (including heap, stack, code snippet)

Under 32-bit platforms, each process has 4GB of virtual memory.

Due to the opening and loading of the process, the operating system must switch the context, so the consumption of resources is relatively large.

Multiple threads of the same process are shared resources.

So the preferred is to use multithreading instead of multiple processes.

The thread consists of two parts;

1, the kernel object, the essence is a data structure, by the operating system management

2. Thread's own stack

There are two types of Windows platform online

Worker thread interface thread

The two are not much different in nature, just the worker thread does not have a message loop

Because static variables and global variables are placed in the memory static zone

Parsing from a compilation perspective is a data segment that is independent of the code snippet and allocates memory at compile time

That way , multiple threads share these resources. Which means that multiple threads can access both static and global variables

Therefore, you should pay attention to thread safety when accessing static and global variables in multiple threads.

There are several ways to troubleshoot thread safety issues:

Thread synchronization implementations have mutexes, event objects, key code snippets

Mutexes and Event objects belong to kernel objects that are managed directly by the operating system

More complex to use more resources

The key code snippet is the user object

Simple to use with less resources

But it's easy to cause thread deadlock

Note the thread deadlock problem when another key code is included in the key code snippet

As follows:

Thread 1 owns object a preemption object B

Thread 2 owns object b preemption Object A

One example is a good description of thread deadlock issues:

Philosophers Dine

3 Philosophers of ethyl C dined at the same time, but each had only one chopstick. So everyone can't eat.

If one of the philosophers handed out his chopsticks to two other philosophers, such as to B, then B would be able to dine.

b after eating a little, the chopsticks handed out to C, and then take turns to use. Can solve the problem of eating.

But these philosophers are more selfish and stubborn, and no one is allowed to cause deadlocks.

Reading, practicing, thinking, summarizing

Reprint Please specify source: http://www.cnblogs.com/zhuojun/

Yards farm charging station--process and thread

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.