(c + +) Interview in English-threading

Source: Internet
Author: User

Q. What's the process and threads and what ' s the difference between them?

A. A process is an executing program.  One or more threads run in the context of the process. It has a primary thread.

A thread is the basic unit to which the operating system allocates processor time.

The typical difference is this threads run in a shared memory space, while processes run in separate memory spaces.

Q. What's the thread pool, and how do does it work?

A. A thread pool is a collection of workers threads that efficiently execute asynchronous callbacks on behalf of the Applic ation.

The thread pool is primarily used to reduce the number of application threads and provide management of the worker threads .

??

Q. What is deadlock, Livelock?

A. In operating system, deadlock are a situation which occurs when a thread enters a waiting state because a resouce reques Ted is being held by another waiting process. All of these threads cannot is completed.

A livelock is similar to a deadlock, except the states of the processes involved in the Lovelock cnostantly change wi Th regard to one another, none progressing.

Livelock is a risk with some algorithms, detect and recover from deadlock. If more than one process takes action, the deadlock detection algorithm can be repeatedly triggered.

Q. What ' s mutex?

A. A mutex object is A Synchroniztion object whose state was set to signaled when it was not owned by any thread, and Nonsi Gnaled when it was owned. For example, to prevent-threads from writing to shared memory at the same time. Each thread waits for ownership of a Mutexes object before executing the code that accesses the memory. After writing to the shared memory, the thread releases the mutex object.

Q. What is producer-consumer problem?

A.  is A classic example of a multi-processes synchronization problem. The probem describes the processes, the producer and the consumer, who share a common, fixed-size buffer used as a queue.  the producer ' s job is to generate a piece of data, put it into the buffer and start again. At the same time, the consumer is consuming the data. (i.e. removing it from the buffer) one piece at a time. The problem is to make sure that the producer won ' t try to add data into the buffer if it's full and that the consumer won ' t try to remove the data from an empty buffer.

The solution for the producer are to either go to sleep or discard data if the buffer was full. The next time the Consuer removes an item from the buffer, it notified the producer, who starts to fill the buffer again. In the same, the consumer can go to sleep if it finds the buffer to be empty.  The next time the producer puts data into the buffer, it wakes up the sleeping consumer. The solution can reached by means of inter-process communication, typically using semaphores.

(c + +) Interview in English-threading

Related Article

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.