(C/C++) Interview in English - Threading

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 that threads run in a shared memory space, while processes run in separate memory spaces.

Q. What‘s thread pool, and how does it work?

A. A thread pool is a collection of worker threads that efficiently execute asynchronous callbacks on behalf of the application.

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 is a situation which occurs when a thread enters a waiting state because a resouce requested is being held by another waiting process. All of these threads cannot be completed.

A livelock is similar to a deadlock, except that the states of the processes involved in the lovelock cnostantly change with regard to one another, none progressing.

Livelock is a risk with some algorithms that 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 is set to signaled when it is not owned by any thread, and nonsignaled when it is owned. For example, to prevent two threads from writing to shared memory at the same time. each thread waits for ownership of a mutex 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 two 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 data from an empty buffer.

The solution for the producer is to either go to sleep or discard data if the buffer is 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 way, 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 be reached by means of inter-process communication, typically using semaphores.

时间: 2024-10-24 22:17:06

(C/C++) Interview in English - Threading的相关文章

(C++) Interview in English. - Constructors/Destructors

Constructors/Destructors. 我们都知道,在C++中建立一个类,这个类中肯定会包括构造函数.析构函数.复制构造函数和重载赋值操作:即使在你没有明确定义的情况下,编译器也会给你生成这样的四个函数.例如以下类: class CTest { public: CTest(); // 构造函数 Constructor ~CTest(); // 析构函数 Destructor CTest(const CTest &); // 拷贝构造函数 Copy Constructor. CTest

(C/C++) Interview in English - Class

Q: What is a class? A: A class is an expanded concept of a data structure: instead of holding only data, it can hold both data and functions. Q: What are the differences between a C++ struct and C++ class? A: The default member and base class access

(C/C++) Interview in English - Basic concepts.

Question Key words Anwser A assignment operator abstract class It is a class that has one or more pure virtual functions. assignment & initialization constructed -> change value ,Same time Assignment changes the value of the object that has already

(C/C++ )Interview in English - Virtual

Q: What is virtual function?A: A virtual function or virtual method is a function or method whose behavior can be overridden within an inheriting class by a function with the same signature. This concept is an important part of the polymorphism porti

Study Plan - The Fifty-Five Day

Time flies, I have not write blogs nearly 3 years. Now I want to write it continue. I remember Why I write a diary. For my dream is join in Microsoft, and have a chance to go aboard. Althouth my current income is good, but it is not fit my real desir

English interview!

Q1:Why are you interested in working for our company?为什么有兴趣在我们公司工作?A1:Because your company has a good sales record. 因为你们公司有良好的销售记录 .A2:Because your operations are global, so I feel I can gain the most from working in this kind of environment.因为你们公司的运

C# Interview Questions:C#-English Questions

This is a list of questions I have gathered from other sources and created myself over a period of time from my experience, many of which I felt where incomplete or simply wrong.  I have finally taken the time to go through each question and correct

Today's interview of C#

I think they are advanced topics. C# 1. when will you use list, when will you use hashtable. 2. when will you use Idispose. 3. Async and Await public async Task<string> DoAsync5()        {           Task<string> mytask=Task.Run<string>((

《Cracking the Coding Interview》——第17章:普通题——题目7

2014-04-28 23:28 题目:给定一个数字,用英语把它读出来. 解法:ZOJ上有相反的题目.如果我要用中文读书来呢? 代码: 1 // 17.7 Read an integer in English. 2 #include <map> 3 #include <string> 4 using namespace std; 5 6 map<int, string> m; 7 8 void init() 9 { 10 m[0] = "zero";