https://www.ruanyifeng.com/blog/2013/05/)
字符串匹配是计算机的基本任务之一。
举例来说,有一个字符串"BBC ABCDAB ABCDABCDABDE",我想知道,里面是否包含另一个字符串"ABCDABD"?
https://www.ruanyifeng.com/blog/2013/05/)
字符串匹配是计算机的基本任务之一。
举例来说,有一个字符串"BBC ABCDAB ABCDABCDABDE",我想知道,里面是否包含另一个字符串"ABCDABD"?
首先看如下代码:
package com.nrsc.ch2.cas;
import java.util.ArrayList;
import java.util.List;
public class CasDemo {
//共享资源
static int i = 0;
public static void increase() {
i++;
}
public static void main(String[] args) throws InterruptedException {
Runnable r = () -> {
for (int j = 0; j < 1000; j++) {
increase();
}
};
List<Thread> threads = new ArrayList<>();
for (int j = 0; j < 10; j++) {
Thread thread = new Thread(r);
threads.add(thread);
thread.start();
}
//确保前面10个线程都走完
for (Thread thread : threads) {
thread.join();
}
System.out.println(i);
}
}
123456789101112131415161718192021222324252627282930313233343536
相信每个人都知道这段代码由于i++不是原子操作
,因此会导致这10个线程执行后的最终结果不是10*1,000 = 10,000。
当然也相信几乎所有人都知道通过加锁可以解决这个问题
,加锁方式解决该问题的原理基本可以用下图进行概况:
而其实除了加锁之外利用CAS机制也能解决这个问题。既然说它是除了加锁之外的另一种解决方式,
那它肯定是无锁的
,因此利用CAS机制解决该问题的方式大致可以用下图进行概况:
那到底啥是CAS呢?它又是是如何解决这个问题的呢?
它是一个数据管道,可以往里面写数据,从里面读数据。
channel 是 goroutine 之间数据通信桥梁,而且是线程安全的。
To duplicate a slice in Go, getting a deep copy of its contents, you need to either use the built-in copy()
function, or create a new empty slice and add all the elements of the first slice to it using the append()
function. Because of how slices are built in Go, assigning one slice to another only makes a shallow copy, and you should not use it if you want to clone the slice in a deep way.
timedatectl list-timezones
sudo timedatectl set-timezone Asia/Shanghai
或者 sudo timedatectl set-timezone Asia/Hong_Kong
date
apt-get install ntp
ntpdate time.nist.gov
1首先通过命令查看samba的安装情况 rpm -ql | grep samba 查看centos版本 [root@localhost ~]# rpm -q centos-release centos-release-8.1-1.1911.0.8.el8.x86_64 2在线安装samba服务器 yum -y install samba3查看samba服务配置文件 root@localhost ~]# gedit /etc/samba/smb.conf 配置文件内容如下
在编译alsa的时候报错,config完毕后,make错误如下: line 81: automake-1.16: command not found
而我的automke的版本为1.15
于是卸载了这个automake后,http://ftp.gnu.org/gnu/automake/下载了最新的1.16,然后安装,然后继续编译alsa,报错:
GitLab社区版部署
GitLab配置禁用创建组权限
GitLab配置邮件(SMTP)
Gitlab备份配置
GitLab常用命令说明
GitLab一个开源的git仓库管理平台,方便团队协作开发、管理。在GitLab上可以实现完整的CI(持续集成)、CD(持续发布)流程。而且还提供了免费使用的Plan,以及免费的可以独立部署的社区版本(https://gitlab.com/gitlab-org/gitlab-ce )。官网:https://about.gitlab.com/