【深入浅出Java并发编程指南】「难点 - 核心 - 遗漏」让我们一起探索一下CyclicBarrier的技术原理和源码分析

news2024/9/20 5:55:20

CyclicBarrier和CountDownLatch

CyclicBarrier和CountDownLatch 都位于java.util.concurrent这个包下,其工作原理的核心要点:

CyclicBarrier工作原理分析

那么接下来给大家分享分析一下JDK1.8的CyclicBarrier的工作原理。

简单认识CyclicBarrier

何为CyclicBarrier?

  1. CyclicBarrier从英文字面上理解,循环栅栏,咋一看好像跟同步器没多大关系,而栅栏式一排排的阻拦着,好像也有点同步等待的意思;

  2. CyclicBarrier是也一种同步帮助工具,允许多个线程相互等待,即多个线程到达同步点时被阻塞,直到最后一个线程到达同步点时栅栏才会被打开;

  3. CyclicBarrier内部没有所谓的公平锁\非公平锁的静态内部类,只是利用了ReentrantLock(独占锁)、ConditionObject(条件对象)实现了线程之间相互等待的功能;

CyclicBarrier的state关键词

  1. CyclicBarrier这个类没有真正的state关键词,它只有parties线程总数量,count还没有进入阻塞的线程数量;

  2. CyclicBarrier的实现是间接利用了ReentrantLock(独占锁)的父类AQS的state变量值;

  3. CountDownLatch,A、B、C组线程同时执行,A先执行完的话就在那里等着,等所有A、B、C线程中执行最久的线程执行完了才开始执行各自的事件;

常用重要的方法


 // 创建给定数值的栅栏总数,也就是支持参与线程的最多数值
public CyclicBarrier(int parties)

// 创建给定数值的栅栏总数,也就是支持参与线程的最多数值,且当最后一个线程执行完时会回调barrierAction方法
public CyclicBarrier(int parties, Runnable barrierAction)

// 更新换代,改朝换代,触发唤醒所有在Lock对象上等待的线程,释放所有正在处于阻塞的线程
private void nextGeneration()

// 打破平衡,并设置打破平衡的标志,然后再唤醒所有被阻塞的线程,
private void breakBarrier() 

// 导致当前线程阻塞,直到其他线程调用trip.signal()或trip.signalAll()方法唤醒该线程
public int await()

// 比await()多了两个参数,意思就是阻塞等待信号量的最大时长,等待的时间值为timeout,单位为unit;
public int await(long timeout, TimeUnit unit)

// 阻塞等待的核心方法,如果不需要超时等待信号量的话则nanos参数是没用的,否则就有用
private int dowait(boolean timed, long nanos)

// 线程之间的等待,这样一个等待的平衡体系是否被打破
public boolean isBroken() 

// 重置为初始状态值,就像初始创建CyclicBarrier该实例对象一样,干干净净的初始状态值
public void reset()

// 获取目前正在处于阻塞状态的线程数量值
public int getNumberWaiting()

// 获取线程数量,也就是栅栏数量总数值
public int getParties()

设计与实现伪代码

等待被释放:

    public int await() throws InterruptedException, BrokenBarrierException {
        try {
            return dowait(false, 0L);
        } catch (TimeoutException toe) {
            throw new Error(toe); // cannot happen
        }
    }

阻塞等待的核心方法;

  • 内部会调用trip.await()方法进入Condition等待阻塞队列;
  • 一旦栅栏数量为零时则会逐个逐个将Condition等待的队列转移到CLH的等待阻塞队列;
  • 所有线程被唤醒后然后等待dowait方法内部lock.unlock()一个个释放线程等待;
  • 阻塞的最后一个线程还有机会执行构造方法传入的接口回调;

CyclicBarrier生活细节化理解

比如百米赛跑,我就以赛跑为例生活化阐述该CyclicBarrier原理,场景:百米赛跑十人参赛,终点处有一个裁判计数;

  • 开跑一声枪响,十个人争先恐后的向终点跑去,真的是振奋多秒,令人振奋;

  • 当一个人到达终点,这个人就完成了他的赛跑事情了,就没事一边玩去了,那么裁判则减去一个人;

  • 随着人员陆陆续续的都跑到了终点,最后裁判计数显示还有0个人未到达,意思就是人员都达到了;

  • 然后裁判就拿着登记的成绩屁颠屁颠去输入电脑登记了;

  • 到此打止,这一系列的动作认为是A组线程等待另外其他组线程的操作,直到计数器为零,那么A则再干其他事情;

源码分析CyclicBarrier

CyclicBarrier构造器

构造器源码

创建一个给定数值的栅栏总数,也就是支持参与线程的最多数值,但是构造方法二还可以通过传入接口回调,当最后一个阻塞的线程被释放后,它将有机会执行这个被传入的回调接口barrierAction;

    /**
     * Creates a new {@code CyclicBarrier} that will trip when the
     * given number of parties (threads) are waiting upon it, and
     * does not perform a predefined action when the barrier is tripped.
     *
     * @param parties the number of threads that must invoke {@link #await}
     *        before the barrier is tripped
     * @throws IllegalArgumentException if {@code parties} is less than 1
     */
    public CyclicBarrier(int parties) {
        this(parties, null);
    }
    /**
     * Creates a new {@code CyclicBarrier} that will trip when the
     * given number of parties (threads) are waiting upon it, and which
     * will execute the given barrier action when the barrier is tripped,
     * performed by the last thread entering the barrier.
     *
     * @param parties the number of threads that must invoke {@link #await}
     *        before the barrier is tripped
     * @param barrierAction the command to execute when the barrier is
     *        tripped, or {@code null} if there is no action
     * @throws IllegalArgumentException if {@code parties} is less than 1
     */
    public CyclicBarrier(int parties, Runnable barrierAction) {
        if (parties <= 0) throw new IllegalArgumentException();
        this.parties = parties;
        this.count = parties;
        this.barrierCommand = barrierAction;
    }

await()

  • 阻塞等待的核心方法,内部会调用trip.await()方法进入Condition等待阻塞队列,一旦栅栏数量为零时则会逐个逐个将Condition等待的队列转移到CLH的等待阻塞队列;

  • 所有线程被唤醒后然后等待dowait方法内部lock.unlock()一个个释放线程等待,阻塞的最后一个线程还有机会执行构造方法传入的接口回调;

    /**
     * Waits until all {@linkplain #getParties parties} have invoked
     * {@code await} on this barrier.
     *
     * <p>If the current thread is not the last to arrive then it is
     * disabled for thread scheduling purposes and lies dormant until
     * one of the following things happens:
     * <ul>
     * <li>The last thread arrives; or
     * <li>Some other thread {@linkplain Thread#interrupt interrupts}
     * the current thread; or
     * <li>Some other thread {@linkplain Thread#interrupt interrupts}
     * one of the other waiting threads; or
     * <li>Some other thread times out while waiting for barrier; or
     * <li>Some other thread invokes {@link #reset} on this barrier.
     * </ul>
     *
     * <p>If the current thread:
     * <ul>
     * <li>has its interrupted status set on entry to this method; or
     * <li>is {@linkplain Thread#interrupt interrupted} while waiting
     * </ul>
     * then {@link InterruptedException} is thrown and the current thread's
     * interrupted status is cleared.
     *
     * <p>If the barrier is {@link #reset} while any thread is waiting,
     * or if the barrier {@linkplain #isBroken is broken} when
     * {@code await} is invoked, or while any thread is waiting, then
     * {@link BrokenBarrierException} is thrown.
     *
     * <p>If any thread is {@linkplain Thread#interrupt interrupted} while waiting,
     * then all other waiting threads will throw
     * {@link BrokenBarrierException} and the barrier is placed in the broken
     * state.
     *
     * <p>If the current thread is the last thread to arrive, and a
     * non-null barrier action was supplied in the constructor, then the
     * current thread runs the action before allowing the other threads to
     * continue.
     * If an exception occurs during the barrier action then that exception
     * will be propagated in the current thread and the barrier is placed in
     * the broken state.
     *
     * @return the arrival index of the current thread, where index
     *         {@code getParties() - 1} indicates the first
     *         to arrive and zero indicates the last to arrive
     * @throws InterruptedException if the current thread was interrupted
     *         while waiting
     * @throws BrokenBarrierException if <em>another</em> thread was
     *         interrupted or timed out while the current thread was
     *         waiting, or the barrier was reset, or the barrier was
     *         broken when {@code await} was called, or the barrier
     *         action (if present) failed due to an exception
     */
    public int await() throws InterruptedException, BrokenBarrierException {
        try {
            return dowait(false, 0L); // 阻塞的核心方法,重心再次,通过ReentrantLock和Condition组合完成阻塞等待
        } catch (TimeoutException toe) {
            throw new Error(toe); // cannot happen
        }
    }

dowait(false, 0L); // 阻塞的核心方法,重新再次,通过ReentrantLock和Condition组合完成阻塞等待

3.3、dowait(boolean, long)

  • dowait方法是CyclicBarrier实现阻塞等待的核心方法,当await方法被调用时阻塞等待被Condition的一个队列维护着;
  • 然而线程从await跳出来时,正常情况下一般都是由于发送了信号量,阻塞被解除,那么Condition的等待队列将会被转移至AQS的等待队列;
  • 然后一个逐渐锁释放,最后CyclicBarrier也处于了初始值状态,供下次调用使用;
  • 因此CyclicBarrier每用完一套整个流程,又会回到初始状态值,又可以被其他地方当做新创建的对象一样来使用,所以才成为循环栅栏;
    /**
     * Main barrier code, covering the various policies.
     */
    private int dowait(boolean timed, long nanos)
        throws InterruptedException, BrokenBarrierException,
               TimeoutException {
        final ReentrantLock lock = this.lock; // 获取独占锁
        lock.lock(); // 通过lock其父类AQS的CLH队列阻塞在此,但是为啥又会继续往下进入临界区执行try方法,其原因就是trip.await()这句代码
        try {
            final Generation g = generation;

            if (g.broken) // 若平衡被一旦打破,则其他所有的线程都会抛出异常,因为即使这里没遇到抛异常,下面还会有 if (g.broken) 判断
                throw new BrokenBarrierException();

            if (Thread.interrupted()) { // 检测线程是否在其他地方被中断过,若任何一个线程被中断过
                breakBarrier(); // 那么则打破平衡,并设置打破平衡的标志,还原初始状态值,然后再唤醒所有被阻塞的线程,
                throw new InterruptedException();
            }

            int index = --count; // 执行一个则减1操作,正常情况下count表示还有多少个未进入临界区,即还在lock阻塞队列中
            if (index == 0) {  // tripped 当count值降为0后,则表明所有线程都执行完了,那么就可以happy的一起改朝换代去做其他事情了
                boolean ranAction = false;
                try {
                    final Runnable command = barrierCommand; // 构造方法传入的接口回调对象
                    if (command != null) // 当接口不为空时,最后一个执行的线程有机会消费该回调方法
                        command.run();
                    ranAction = true;
                    nextGeneration(); // 改朝换代,该执行的都已经执行完了,还原为初始状态值,以便下次可以重复再次使用
                    return 0;
                } finally {
                    if (!ranAction) // 若最后一个线程眼看着要完事了,若出现了任何异常的话,也照样打破整体平衡,要么一起生要么一起亡
                        breakBarrier();
                }
            }

            // loop until tripped, broken, interrupted, or timed out
            for (;;) { // 自旋的死循环操作方式
                try {
                    if (!timed) // 若不需要使用超时等待信号量的话,那么下面就直接调用trip.await()进入阻塞等待
                        trip.await(); // 正常情况下,代码执行到此就不动了,该方法内部已经调用了park方法导致线程阻塞等待
                    else if (nanos > 0L)
                        nanos = trip.awaitNanos(nanos); // 在指定时间内等待信号量
                } catch (InterruptedException ie) { // 若在阻塞等待期间由于被中断了
                    if (g == generation && ! g.broken) { // 如果还没改朝换代,并且平衡标志位还为false的话,则继续打破平衡并且抛出中断异常
                        breakBarrier();
                        throw ie;
                    } else {
                        // We're about to finish waiting even if we had not
                        // been interrupted, so this interrupt is deemed to
                        // "belong" to subsequent execution.
                        Thread.currentThread().interrupt();
                    }
                }
                if (g.broken) // 这里也有 if (g.broken) 判断,若平衡被一旦打破,则其他所有的线程都会抛出异常
                    throw new BrokenBarrierException();

                if (g != generation) // 若已经被改朝换代了,那么则直接返回index值
                    return index;

                if (timed && nanos <= 0L) { // 若设置了超时标志,并且不管是传入的nanos值也好还是通过等待后返回的nanos也好,只要小于或等于零都会打破平衡
                    breakBarrier();
                    throw new TimeoutException();
                }
            }
        } finally {
            lock.unlock(); // 释放lock锁
        }
    }

breakBarrier()

打破平衡,并设置打破平衡的标志,然后再唤醒所有被阻塞的线程;

    /**
     * Sets current barrier generation as broken and wakes up everyone.
     * Called only while holding lock.
     */
    private void breakBarrier() {
        generation.broken = true; // 设置打破平衡的标志
        count = parties; // 重新还原count为初始值
        trip.signalAll(); // 发送信号量,唤醒所有Condition中的等待队列
    }

nextGeneration()

唤醒所有在Condition中等待的队列,然后还原初始状态值,并且重新换掉generation的引用,改朝换代,为下一轮操作做准备;

/**
     * Updates state on barrier trip and wakes up everyone.
     * Called only while holding lock.
     */
    private void nextGeneration() {
        // signal completion of last generation
        trip.signalAll();
        // set up next generation
        count = parties;
        generation = new Generation();
    }

AQS的await()

CyclicBarrier的成员属性 trip( Condition类型 ) 对象的方法:

  1. 该AQS的await方法,因为该方法涉及到为什么用了独占锁lock.lock之后,dowait方法里面通过调用了trip.await()进行阻塞的话,第二个、第三个线程怎么还会通过lock.lock调用之后还能进入临界区呢。
  2. AQS的方法会调用fullyRelease(node)释放当前线程占有的锁,所以lock.lock才不至于一直被阻塞在那里;
  3. 并且Condition也维护了自己的一个链表,凡是通过调用trip.await()方法的线程,都会首先进入Condition的队列,然后释放独占锁,想办法调用park方法锁住当前线程;
  4. 然后在被信号量通知的时候,又会将Condition队列的结点转移到AQS的同步队列中,然后等待调用unlock逐个释放锁;
	/**
	 * Implements interruptible condition wait.
	 * <ol>
	 * <li> If current thread is interrupted, throw InterruptedException.
	 * <li> Save lock state returned by {@link #getState}.
	 * <li> Invoke {@link #release} with saved state as argument,
	 *      throwing IllegalMonitorStateException if it fails.
	 * <li> Block until signalled or interrupted.
	 * <li> Reacquire by invoking specialized version of
	 *      {@link #acquire} with saved state as argument.
	 * <li> If interrupted while blocked in step 4, throw InterruptedException.
	 * </ol>
	 */
	public final void await() throws InterruptedException {
		if (Thread.interrupted())
			throw new InterruptedException();
		Node node = addConditionWaiter(); // 将当前线程包装一下,然后添加到Condition自己维护的链表队列中
		int savedState = fullyRelease(node); // 释放当前线程占有的锁,如果不释放的话,那么在第二次调用lock.lock()的地方;
		// 如果第一个没执行完的话,那么则会一直阻塞等待,那么也就无法完成栅栏的功能了。
		int interruptMode = 0;
		while (!isOnSyncQueue(node)) { // 是否在AQS的队列中
			LockSupport.park(this); // 如果不在AQS队列中的话,则阻塞等待,这里才是最最最核心阻塞的地方
			if ((interruptMode = checkInterruptWhileWaiting(node)) != 0)
				break;
		}
		// 如果在AQS队列中的话,那么则考虑重入锁,重新竞争锁,重新休息
		if (acquireQueued(node, savedState) && interruptMode != THROW_IE)
			interruptMode = REINTERRUPT;
		if (node.nextWaiter != null) // clean up if cancelled
			unlinkCancelledWaiters();
		if (interruptMode != 0)
			reportInterruptAfterWait(interruptMode);
	}

CyclicBarrier的实战用法

CyclicBarrier提供2个构造器:

public CyclicBarrier(int parties, Runnable barrierAction) {}
public CyclicBarrier(int parties) {}
  • parties:指让多少个线程或者任务等待至barrier状态;
  • barrierAction:当这些线程都达到barrier状态时会执行的内容。

CyclicBarrier中最重要的方法就是await方法

//挂起当前线程,直至所有线程都到达barrier状态再同时执行后续任务;
public int await() throws InterruptedException, BrokenBarrierException { };

//让这些线程等待至一定的时间,如果还有线程没有到达barrier状态就直接让到达barrier的线程执行后续任务
public int await(long timeout, TimeUnit unit)throws InterruptedException,BrokenBarrierException,TimeoutException { };
public class cyclicBarrierTest {
    public static void main(String[] args) throws InterruptedException {
        CyclicBarrier cyclicBarrier = new CyclicBarrier(5, new Runnable() {
            @Override
            public void run() {
                System.out.println("线程组执行结束");
            }
        });
        for (int i = 0; i < 5; i++) {
            new Thread(new readNum(i,cyclicBarrier)).start();
        }
    }
    static class readNum  implements Runnable{
        private int id;
        private CyclicBarrier cyc;
        public readNum(int id,CyclicBarrier cyc){
            this.id = id;
            this.cyc = cyc;
        }
        @Override
        public void run() {
            synchronized (this){
                System.out.println("id:"+id);
                try {
                    cyc.await();
                    System.out.println("线程组任务" + id + "结束,其他任务继续");
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }
}

输出结果:

id:1
id:2
id:4
id:0
id:3
线程组执行结束
线程组任务3结束,其他任务继续
线程组任务1结束,其他任务继续
线程组任务4结束,其他任务继续
线程组任务0结束,其他任务继续
线程组任务2结束,其他任务继续

总结

  1. 有了分析CountDownLatch、Semaphore的基础后,再来分析CyclicBarrier显然有了扎实的功底,分析起来顺手多了;
  2. 在这里我简要总结一下CyclicBarrier的流程的一些特性:
    • 用途让一组线程互相等待,直到都到达公共屏障点才开始各自继续做各自的工作;
    • 可重复利用,每正常走完一次流程,或者异常结束流程,那么接下来一轮还是可以继续利用CyclicBarrier实现线程等待功能;
    • 共存亡,只要有一个线程有异常发生中断,那么其它线程都会被唤醒继续工作,然后接着就是抛异常处理;

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/58586.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Nginx动静分离、缓存配置、性能调优、集群配置

一. Nginx动静分离 1. 准备 1个web程序&#xff1a;部署在7061端口&#xff0c;启动 【dotnet NginxWeb.dll --urls"http://*:7061" --ip"127.0.0.1" --port7061】 Nginx程序&#xff1a;监听7000端口 2. 目的 比如单独启动部署在7061端口下的web程序&am…

c++ 静态库,动态库的制作和使用

文章目录1.什么是库&#xff1f;2.静态库的制作1.静态库的命名规则2.静态库的制作与使用1.静态库的制作2.静态库的使用3.动态库的制作1.动态库的命名规则2.动态库的制作与使用1.动态库的制作2.动态库的使用3.动态库加载失败的原因4.静态库和动态库的对比1.程序编译成可执行文件…

[附源码]Python计算机毕业设计Django基于Java的失物招领平台

项目运行 环境配置&#xff1a; Pychram社区版 python3.7.7 Mysql5.7 HBuilderXlist pipNavicat11Djangonodejs。 项目技术&#xff1a; django python Vue 等等组成&#xff0c;B/S模式 pychram管理等等。 环境需要 1.运行环境&#xff1a;最好是python3.7.7&#xff0c;…

时序数据库选型

目录一、当前主流的时序数据库二、各库特性1、Influxdb2、Timescale3、Druid4、Kdb5、Graphite6、RRDtool7、OpenTSDB8、TDengine9、DolphinDB三、优缺点对比因为个人用的go&#xff0c;所以调研及对比主要针对适配了go语言的数据库。 一、当前主流的时序数据库 排名参考于h…

基于PHP+MySQL动漫专题网站系统的设计与实现

随着时代的发展&#xff0c;人们兴趣爱好也越来越广泛&#xff0c;动漫是当前年轻人比较钟爱的一个兴趣爱好之一&#xff0c;每年都会有大量的动漫爱好者定期的举办一些交流活动等&#xff0c;但是线下的这种交流方式明显不能满足当前动漫爱好者的需求&#xff0c;为此我开发了…

Zen of Python(python之禅)

在python中导入import this就会显式&#xff1a; 以下是中文英文翻译&#xff1a; Beautiful is better than ugly. 优美比丑陋好 Explicit is better than implicit. 清晰比晦涩好 Simple is better than complex. 简单比复杂好 Complex is better than complicated. 复杂比错…

【全干工程师必学】一文搞懂Vue2.0

一文搞懂Vue2.0一、前端工程化二、WebPack是什么基本使用实现奇偶行变色1.初始化包管理工具2.安装jquery3.在项目中安装webpack4.在项目中配置webpack5.运行代码mode 的可选值developmentproductionwebpack.config.js 文件的作用webpack 中的默认约定自定义打包的入口与出口web…

uni-app开发常用操作速查记录

记录一下uni-app中常用的使用方法或是操作步骤,方便后期速查使用. 1.设置对象属性 2.组件中数据变化监听方法 3.微信开发者工具中全局搜索与局部搜索 4.Page对象与Componet对象组成 5.tabbar页面切换方法 6.组件中自定义函数的参数传递 7.m…

Android Jetpack Compose的基本介绍

目录一、引言&#xff1a;Android Jetpack1.Jetpack是什么&#xff1f;2. 常用的Jetpack库二、Compose的基本概念1.什么是Jetpack Compose2.Compose的编程思想三、 Compose简单的案例: 一个倒计时效果1.构建一个Compose项目2.声明一个倒计时的UI3.利用线程使其动起来4.实现效果…

快速了解Docker

目录 1.简介 2.Docker的安装及环境配置 2.1.查看是否是root用户 2.2.查看当前内核版本 2.3.更新yum源 2.4.安装Docker所需要的工具包 2.5.设置yum源 2.6.下载安装Docker 2.7.启动Docker并且设置开机自启动 2.8.测试是否安装成功 3.Docker阿里云镜像仓库配置 4.Docker常…

C++ vector

目录 1.vector的介绍及使用 1.1 vector的介绍 1.2 vector的使用 1.2.1 vector的定义 1.2.2 vector iterator 的使用 1.2.3 vector 空间增长问题 1.2.3 vector 增删查改 1.2.4 vector 迭代器失效问题。&#xff08;重点&#xff09; 1.2.5 vector 在OJ中的使用 2.vec…

【Linux】Linux的常见指令详解(上)

目录 前言 ls pwd cd mkdir touch rm man tree nano cp mv cat echo more/less 前言 &#x1f9c1;Linux作为相较于windows的另一种操作系统&#xff0c;同时基于其开源的优越性&#xff0c;使得其在各各企业的使用率极高。因此学好Linux操作系统对我们来说是…

Mongoose应用和文件文件的上传和下载

一、Express框架访问MongoDB数据库 1、目的&#xff1a; ​ &#xff08;1&#xff09;mongoose模块的使用 ​ &#xff08;2&#xff09;学会代码的封装&#xff1a;dao层、service层、接口层 ​ &#xff08;3&#xff09;MVC设计思想&#xff1a;M(Model)、V(View)、C(C…

[附源码]Python计算机毕业设计Django基于SpringBoot的演唱会购票系统论文2022

项目运行 环境配置&#xff1a; Pychram社区版 python3.7.7 Mysql5.7 HBuilderXlist pipNavicat11Djangonodejs。 项目技术&#xff1a; django python Vue 等等组成&#xff0c;B/S模式 pychram管理等等。 环境需要 1.运行环境&#xff1a;最好是python3.7.7&#xff0c;我…

c#与mysql连接和操作教程(增、删、改、查)

一、mysql的连接&#xff08;使用的是vs2019&#xff09; 1. 在一个项目中选择 工具 > NgtGet包管理器 > 管理解决方案的NuGet程序包 2. 搜索MySql.Data&#xff0c;然后下载&#xff0c;并在右边选着对应的项目进行安装&#xff08;ps&#xff1a;每个项目要连接数据库…

【身份证识别】基于BP神经网络实现身份证识别附matlab代码

✅作者简介&#xff1a;热爱科研的Matlab仿真开发者&#xff0c;修心和技术同步精进&#xff0c;matlab项目合作可私信。 &#x1f34e;个人主页&#xff1a;Matlab科研工作室 &#x1f34a;个人信条&#xff1a;格物致知。 更多Matlab仿真内容点击&#x1f447; 智能优化算法 …

代码随想录刷题|LeetCode 300.最长递增子序列 674. 最长连续递增序列 718. 最长重复子数组

目录 300.最长递增子序列 思路 1、dp[i]的定义 2、递推公式 3、dp数组初始化 4、确定遍历顺序 5、推导dp数组 最长递增子序列 674. 最长连续递增序列 思路 最长连续递增序列 动态规划 贪心算法 718. 最长重复子数组 思路 1、确定dp数组的含义 2、确定递推公式 3、dp数组初始化…

docker 命令

目录 Docker 环境信息命令 docker info docker version 系统日志信息常用命令 docker events docker logs docker history 容器的生命周期管理命令 docker create docker run 常用选项 系统 网络 健康检查 命名空间选项 cgroup资源限制选项 CPU CPUset devi…

李宏毅《DLHLP》学习笔记7 - Voice Conversion 1

视频链接&#xff1a;https://www.youtube.com/watch?vJj6blc8UijY&listPLJV_el3uVTsO07RpBYFsXg-bN5Lu0nhdG&index9&ab_channelHung-yiLee 课件链接&#xff1a;https://speech.ee.ntu.edu.tw/~tlkagk/courses/DLHLP20/Voice%20Conversion%20(v3).pdf 1. 语音转…

永磁同步电机恒压频比(V/F)开环控制系统Matlab/Simulink仿真分析及代码生成到工程实现(二)

文章目录前言一、SVPWM二、永磁同步电机恒压频比开环控制系统Matlab/Simulink仿真分析2.1.仿真电路分析2.1.1.恒压频比控制算法2.1.2.输出处理2.1.3.主电路2.2.仿真结果分析三、永磁同步电机恒压频比开环控制系统代码生成及工程实现3.1.恒压频比开环控制算法代码生成3.2.仿真验…