• 阻塞,非阻塞,异步,同步,单线程,多线程


    什么是阻塞式?什么是非阻塞式?

    我理解的不是很对,咨询了谷歌大师,知道以下几点:

    1. 阻塞与非阻塞式跟网络编程有关

    2. 当服务端与客户端建立连接时,如果客户端还没有接收到服务器端的响应,客户端程序不继续往下运行,此时会被挂起,直至有结果返回,这个就是阻塞式编程

    3. 非阻塞式跟阻塞式相反,当没有接收到响应时,程序会继续运行,当有响应时,操作系统会通知程序回头处理。

    什么是单线程?什么是多线程?

    我理解的也不是很对,来自维基百科的解释:

    In computer science, a thread of execution is the smallest unit of processing that can be scheduled by an operating system. A thread is a lightweight process. The implementation of threads and processes differs from one operating system to another, but in most cases, a thread is contained inside a process. Multiple threads can exist within the same process and share resources such as memory, while different processes do not share these resources. In particular, the threads of a process share the latter's instructions (its code) and its context (the values that its variables reference at any given moment).

    On a single processor, multithreading generally occurs by time-division multiplexing (as in multitasking): the processor switches between different threads. This context switching generally happens frequently enough that the user perceives the threads or tasks as running at the same time. On a multiprocessor (including multi-core system), the threads or tasks will actually run at the same time, with each processor or core running a particular thread or task.

    Many modern operating systems directly support both time-sliced and multiprocessor threading with a process scheduler. The kernel of an operating system allows programmers to manipulate threads via the system call interface. Some implementations are called a kernel thread, whereas a lightweight process (LWP) is a specific type of kernel thread that shares the same state and information.

    大概意思:线程是操作系统计划调度的最小处理单元,线程就是轻量级的进程,不同的操作系统线程和进程的实现方式不同。但是,在大多数情况下,线程包含在进程里。在同一进程里,可以存在多个线程,这些线程共享内存等资源,然而不同进程之间不会共享。特别地,同一进程的线程可以共享后者的指令以及上下文环境。

    什么是异步?什么是同步?

    对于异步与同步的概念,自己认识不是深刻,由于自己一直从事web开发,对于异步与同步的理解也只限于浏览器与服务器交互的方式。

    谷歌了一下,发现了以下一些文字:

    所谓同步,可以理解为在执行完一个函数或方法之后,一直等待系统返回值或消息,这时程序是出于阻塞的,只有接收到返回的值或消息后才往下执行其他的命令。  
       
    异步,执行完函数或方法后,不必阻塞性地等待返回值或消息,只需要向系统委托一个异步过程,那么当系统接收到返回值或消息时,系统会自动触发委托的异步过程,从而完成一个完整的流程。 

    转载一链接:同步和异步-大道至简

    JScex异步编程

    花了几天时间看了下源码,没有完全看懂,我对它的理解:帮助委托对象构造计算表达式,然后动态编译成可以异步执行的任务,运行任务,基于任务状态的回调机制。

    JSCEX文档

  • 相关阅读:
    图片懒加载
    浅谈javascript的函数节流
    js字符串常用方法详解
    js数组详解
    thinkphp3.2 批量添加数据
    openssl证书及配置
    手机访问PC端
    mui框架(三)
    mui框架(二)
    mui框架(一)
  • 原文地址:https://www.cnblogs.com/wadeyu/p/2617285.html
Copyright © 2020-2023  润新知