(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.
(C/C++) Interview in English - Threading的更多相关文章
- (C++) Interview in English. - Constructors/Destructors
Constructors/Destructors. 我们都知道,在C++中建立一个类,这个类中肯定会包括构造函数.析构函数.复制构造函数和重载赋值操作:即使在你没有明确定义的情况下,编译器也会给你生成 ...
- (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 pu ...
- (C/C++ )Interview in English - Virtual
Q: What is virtual function?A: A virtual function or virtual method is a function or method whose be ...
- (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 d ...
- (C/C++) Interview in English - Points.
Q: What is a dangling pointer? A: A dangling pointer arises when you use the address of an object af ...
- (C/C++) Interview in English. - Memory Allocation/Deallocation.
Q: What is the difference between new/delete and malloc/free? A: Malloc/free do not know about const ...
- step 1:begin to identify something in english(to becaome a baby again)
long long ago , i think if i want to improve my english especially computer english . i must do so m ...
- English interview!
Q1:Why are you interested in working for our company?为什么有兴趣在我们公司工作?A1:Because your company has a goo ...
- Enginering English for interview (1)
I was lucky to work in a foreign company, Here is an overview of the interview test : 1.Because of t ...
随机推荐
- 共享内存+互斥量实现linux进程间通信 分类: Linux C/C++ 2015-03-26 17:14 67人阅读 评论(0) 收藏
一.共享内存简介 共享内存是进程间通信中高效方便的方式之一.共享内存允许两个或更多进程访问同一块内存,就如同 malloc() 函数向不同进程返回了指向同一个物理内存区域的指针,两个进程可以对一块共享 ...
- 在创建窗口句柄之前,不能在控件上调用 Invoke 或 BeginInvoke 解决办法
增加IsHandleCreated 判断 if (this.IsHandleCreated) { this.Invoke(new EventHandler(delegate { ...... })); ...
- kuangbin_ShortPath I (POJ 2240)
本身很简单的spfa判环 TLE了一把是因为没写map(不会) 看着别人的答案临时学了一发发现只是用的话还是挺简单的 (但是绝对别学别人直接命名为m) 800多MS水过 噢对了这题Pending到超时 ...
- c++特性:指向类成员的指针和非类型类模板参数和函数指针返回值 参数推导机制和关联型别
一.c++允许定义指向类成员的指针,包括类函数成员指针和类数据成员指针 格式如下: class A { public: void func(){printf("This is a funct ...
- Memory Barriers ,cache-coherency
http://www.rdrop.com/users/paulmck/scalability/paper/whymb.2010.07.23a.pdf Shared-Memory Synchroniza ...
- Nginx-SSI
<a href="<!--#include file="/$SERVER_NAME.shtml"-->">点击</a> a
- Linux-内核缓存区和write行为
<Unix环境高级编程> 应用缓冲技术能很明显的提高系统效率.内核与外围设备的数据交换,内核与用户空间的数据交换都是比较费时的,使用缓冲区就是为了优化这些费时的操作.其实核心到用户空间的操 ...
- BP神经网络——交叉熵作代价函数
Sigmoid函数 当神经元的输出接近 1时,曲线变得相当平,即σ′(z)的值会很小,进而也就使∂C/∂w和∂C/∂b会非常小.造成学习缓慢,下面有一个二次代价函数的cost变化图,epoch从15到 ...
- php中定义网站根目录的常用方法
define('BASE_PATH',str_replace('\\','/',realpath(dirname(__FILE__).'/../')));
- SQL Server 索引分类
什么是索引 拿汉语字典的目录页(索引)打比方:正如汉语字典中的汉字按页存放一样,SQL Server中的数据记录也是按页存放的,每页容量一般为4K .为了加快查找的速度,汉语字(词)典一般都有按拼音. ...