• (C/C++) Interview in English


    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.

  • 相关阅读:
    黑马程序员JAVA高级视频_IO输入与输出18天2(FileWriter)
    黑马程序员JavaAPI17天5(集合转成数组)
    黑马程序员JAVA高级视频_IO输入与输出19天4(MyBufferedReader)
    android 取消webview的背景色
    DLNA
    Android JNI的若干问题总结
    gcc 一些应用
    如何基于nand flash启动Linux内核(分享一段实用、简单、类似bootloader功能的代码)
    Android JNI开发高级篇有关Android JNI开发中比较强大和有用的功能就是从JNI层创建、构造Java的类或执行Java层的方法获取属性等操作。 一、类的相关操作 1. jclass FindClass(JNIEnv *env, const char *name);
    ubuntu 配置ndk
  • 原文地址:https://www.cnblogs.com/fdyang/p/4423431.html
Copyright © 2020-2023  润新知