愿星光伴随你左右


  • 首页

  • todo

  • 思考

  • life

  • food

  • OS

  • lua

  • redis

  • Golang

  • C

  • TCP/IP

  • ebpf

  • p4

  • OpenVPN

  • IPSec

  • L2TP

  • DNS

  • distributed

  • web

  • OpenWRT

  • 运维

  • Git

  • 鸟哥的私房菜

  • IT杂谈

  • 投资

  • About Me

  • 友情链接

  • FTP

  • 搜索
close

字符串匹配的KMP算法

时间: 2022-09-29   |   分类: 算法     |   阅读: 1939 字 ~4分钟

https://www.ruanyifeng.com/blog/2013/05/)

字符串匹配是计算机的基本任务之一。

举例来说,有一个字符串"BBC ABCDAB ABCDABCDABDE",我想知道,里面是否包含另一个字符串"ABCDABD"?

阅读全文 »

Compare And Swap(CAS)原理分析

时间: 2022-09-29   |   分类: IT     |   阅读: 3329 字 ~7分钟

1 什么是CAS?


1.1 加锁和CAS解决原子性问题的不同原理

首先看如下代码:

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呢?它又是是如何解决这个问题的呢?

阅读全文 »

golang 中 channel 的详细使用、使用注意事项及死锁分析

时间: 2022-09-29   |   分类: go     |   阅读: 4639 字 ~10分钟

golang 中 channel 的详细使用、使用注意事项及死锁分析

什么是 channel 管道#

它是一个数据管道,可以往里面写数据,从里面读数据。

channel 是 goroutine 之间数据通信桥梁,而且是线程安全的。

阅读全文 »

Copy a slice in Go

时间: 2022-09-29   |   分类: go     |   阅读: 384 字 ~1分钟

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.

阅读全文 »

Ubuntu 20.04 修改时区和同步时间

时间: 2022-09-29   |   分类: 运维     |   阅读: 58 字 ~1分钟

查看系统支持的时区

​ 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

CentOS8上安装 Samba

时间: 2022-09-29   |   分类: 运维     |   阅读: 647 字 ~2分钟

centos 8安装Samba服务器及配置

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 配置文件内容如下

阅读全文 »

Ubuntu linux编译alsa-lib报错 automake-1.16: command not found 的解决方案

时间: 2022-09-29   |   分类: 运维     |   阅读: 285 字 ~1分钟

在编译alsa的时候报错,config完毕后,make错误如下: line 81: automake-1.16: command not found

而我的automke的版本为1.15

于是卸载了这个automake后,http://ftp.gnu.org/gnu/automake/下载了最新的1.16,然后安装,然后继续编译alsa,报错:

阅读全文 »

Gitlib部署简介

时间: 2022-09-29   |   分类: 运维     |   阅读: 2364 字 ~5分钟

一、前言

1、本文主要内容

  • GitLab社区版部署

  • GitLab配置禁用创建组权限

  • GitLab配置邮件(SMTP)

  • Gitlab备份配置

  • GitLab常用命令说明

    2、GitLab介绍

    GitLab一个开源的git仓库管理平台,方便团队协作开发、管理。在GitLab上可以实现完整的CI(持续集成)、CD(持续发布)流程。而且还提供了免费使用的Plan,以及免费的可以独立部署的社区版本(https://gitlab.com/gitlab-org/gitlab-ce )。官网:https://about.gitlab.com/

阅读全文 »
29 30 31 32 33 34 35 36 37

日志
分类
标签
RSS 订阅
GitHub
© 2009 - 2025
粤ICP备2021068940号-1 粤公网安备44011302003059
0%