主頁 > 後端開發 > Rust編程語言入門之無畏并發

Rust編程語言入門之無畏并發

2023-04-20 07:20:21 後端開發

無畏并發

并發

  • Concurrent:程式的不同部分之間獨立的執行(并發)
  • Parallel:程式的不同部分同時運行(并行)
  • Rust無畏并發:允許你撰寫沒有細微Bug的代碼,并在不引入新Bug的情況下易于重構
  • 注意:本文中的”并發“泛指 concurrent 和 parallel

一、使用執行緒同時運行代碼(多執行緒)

行程與執行緒

  • 在大部分OS里,代碼運行在行程(process)中,OS同時管理多個行程,
  • 在你的程式里,各獨立部分可以同時運行,運行這些獨立部分的就是執行緒(thread)
  • 多執行緒運行:
    • 提升性能表現
    • 增加復雜性:無法保障各執行緒的執行順序

多執行緒可導致的問題

  • 競爭狀態,執行緒以不一致的順序訪問資料或資源
  • 死鎖,兩個執行緒彼此等待對方使用完所持有的資源,執行緒無法繼續
  • 只在某些情況下發生的 Bug,很難可靠地復制現象和修復

實作執行緒的方式

  • 通過呼叫OS的API來創建執行緒:1:1模型
    • 需要較小的運行時
  • 語言自己實作的執行緒(綠色執行緒):M:N模型
    • 需要更大的運行時
  • Rust:需要權衡運行時的支持
  • Rust標準庫僅提供1:1模型的執行緒

通過 spawn 創建新執行緒

  • 通過 thread::spawn 函式可以創建新執行緒:
    • 引數:一個閉包(在新執行緒里運行的代碼)
? cd rust

~/rust
? cargo new thread_demo
     Created binary (application) `thread_demo` package

~/rust
? cd thread_demo

thread_demo on  master [?] via ?? 1.67.1
? c # code .

thread_demo on  master [?] via ?? 1.67.1
?

  • thread::sleep 會導致當前執行緒暫停執行
use std::thread;
use std::time::Duration;

fn main() {
    thread::spawn(|| {
        for i in 1..10 {
            println!("hi number {} from the spawned thread!", i);
            thread::sleep(Duration::from_millis(1));
        }
    });

    for i in 1..5 {
        println!("hi number {} from the main thread!", i);
        thread::sleep(Duration::from_millis(1));  // 暫停 1 毫秒
    }
}

執行

thread_demo on  master [?] is ?? 0.1.0 via ?? 1.67.1 
? cargo run            
   Compiling thread_demo v0.1.0 (/Users/qiaopengjun/rust/thread_demo)
    Finished dev [unoptimized + debuginfo] target(s) in 0.65s
     Running `target/debug/thread_demo`
hi number 1 from the main thread!
hi number 1 from the spawned thread!
hi number 2 from the main thread!
hi number 2 from the spawned thread!
hi number 3 from the main thread!
hi number 3 from the spawned thread!
hi number 4 from the spawned thread!
hi number 4 from the main thread!
hi number 5 from the spawned thread!

thread_demo on  master [?] is ?? 0.1.0 via ?? 1.67.1 
? 

通過 join Handle 來等待所有執行緒的完成

  • thread::spawn 函式的回傳值型別是 JoinHandle
  • JoinHandle 持有值的所有權
    • 呼叫其 join 方法,可以等待對應的其它執行緒的完成
  • join 方法:呼叫 handle 的join方法會阻止當前運行執行緒的執行,直到 handle 所表示的這些執行緒終結,
use std::thread;
use std::time::Duration;

fn main() {
    let handle = thread::spawn(|| {
        for i in 1..10 {
            println!("hi number {} from the spawned thread!", i);
            thread::sleep(Duration::from_millis(1));
        }
    });

    for i in 1..5 {
        println!("hi number {} from the main thread!", i);
        thread::sleep(Duration::from_millis(1));  // 暫停 1 毫秒
    }

    handle.join().unwrap();
}

執行

thread_demo on  master [?] is ?? 0.1.0 via ?? 1.67.1 
? cargo run
   Compiling thread_demo v0.1.0 (/Users/qiaopengjun/rust/thread_demo)
    Finished dev [unoptimized + debuginfo] target(s) in 0.75s
     Running `target/debug/thread_demo`
hi number 1 from the main thread!
hi number 1 from the spawned thread!
hi number 2 from the spawned thread!
hi number 2 from the main thread!
hi number 3 from the spawned thread!
hi number 3 from the main thread!
hi number 4 from the spawned thread!
hi number 4 from the main thread!
hi number 5 from the spawned thread!
hi number 6 from the spawned thread!
hi number 7 from the spawned thread!
hi number 8 from the spawned thread!
hi number 9 from the spawned thread!

thread_demo on  master [?] is ?? 0.1.0 via ?? 1.67.1 

等分執行緒執行完繼續執行主執行緒

use std::thread;
use std::time::Duration;

fn main() {
    let handle = thread::spawn(|| {
        for i in 1..10 {
            println!("hi number {} from the spawned thread!", i);
            thread::sleep(Duration::from_millis(1));
        }
    });

    handle.join().unwrap();

    for i in 1..5 {
        println!("hi number {} from the main thread!", i);
        thread::sleep(Duration::from_millis(1)); // 暫停 1 毫秒
    }
}

運行

thread_demo on  master [?] is ?? 0.1.0 via ?? 1.67.1 
? cargo run
   Compiling thread_demo v0.1.0 (/Users/qiaopengjun/rust/thread_demo)
    Finished dev [unoptimized + debuginfo] target(s) in 0.28s
     Running `target/debug/thread_demo`
hi number 1 from the spawned thread!
hi number 2 from the spawned thread!
hi number 3 from the spawned thread!
hi number 4 from the spawned thread!
hi number 5 from the spawned thread!
hi number 6 from the spawned thread!
hi number 7 from the spawned thread!
hi number 8 from the spawned thread!
hi number 9 from the spawned thread!
hi number 1 from the main thread!
hi number 2 from the main thread!
hi number 3 from the main thread!
hi number 4 from the main thread!

thread_demo on  master [?] is ?? 0.1.0 via ?? 1.67.1 

使用 move 閉包

  • move 閉包通常和 thread::spawn 函式一起使用,它允許你使用其它執行緒的資料
  • 創建執行緒時,把值的所有權從一個執行緒轉移到另一個執行緒
use std::thread;

fn main() {
  let v = vec![1, 2, 3];
  let handle = thread::spawn(|| { // 報錯
    println!("Here's a vector: {:?}", v);
  });
  
  // drop(v);
  handle.join().unwrap();
}

修改后:

use std::thread;

fn main() {
  let v = vec![1, 2, 3];
  let handle = thread::spawn(move || { 
    println!("Here's a vector: {:?}", v);
  });
  
  // drop(v);
  handle.join().unwrap();
}

二、使用訊息傳遞來跨執行緒傳遞資料

訊息傳遞

  • 一種很流行且能保證安全并發的技術就是:訊息傳遞,
    • 執行緒(或 Actor)通過彼此發送訊息(資料)來進行通信
  • Go 語言的名言:不要用共享記憶體來通信,要用通信來共享記憶體,
  • Rust:Channel(標準庫提供)

Channel

  • Channel 包含: 發送端、接收端
  • 呼叫發送端的方法,發送資料
  • 接收端會檢查和接收到達的資料
  • 如果發送端、接收端中任意一端被丟棄了,那么Channel 就”關閉“了

創建 Channel

  • 使用 mpsc::channel函式來創建 Channel
    • mpsc 表示 multiple producer,single consumer(多個生產者、一個消費者)
    • 回傳一個 tuple(元組):里面元素分別是發送端、接收端
use std::sync::mpsc;
use std::thread;

fn main() {
  let (tx, rx) = mpsc::channel();
  
  thread::spawn(move || {
    let val = String::from("hi");
    tx.send(val).unwrap();
  });
  
  let received = rx.recv().unwrap();
  println!("Got: {}", received);
}

發送端的 send 方法

  • 引數:想要發送的資料
  • 回傳:Result<T, E>
    • 如果有問題(例如接收端已經被丟棄),就回傳一個錯誤

接收端的方法

  • recv 方法:阻止當前執行緒執行,直到 Channel 中有值被送來
    • 一旦有值收到,就回傳 Result<T, E>
    • 當發送端關閉,就會收到一個錯誤
  • try_recv 方法:不會阻塞,
    • 立即回傳 Result<T, E>:
      • 有資料達到:回傳 Ok,里面包含著資料
      • 否則,回傳錯誤
    • 通常會使用回圈呼叫來檢查 try_recv 的結果

Channel 和所有權轉移

  • 所有權在訊息傳遞中非常重要:能幫你撰寫安全、并發的代碼
use std::sync::mpsc;
use std::thread;

fn main() {
  let (tx, rx) = mpsc::channel();
  
  thread::spawn(move || {
    let val = String::from("hi");
    tx.send(val).unwrap();
    println!("val is {}", val)  // 報錯 借用了移動的值
  });
  
  let received = rx.recv().unwrap();
  println!("Got: {}", received);
}

發送多個值,看到接收者在等待

use std::sync::mpsc;
use std::thread;

fn main() {
  let (tx, rx) = mpsc::channel();
  
  thread::spawn(move || {
    let vals = vec![
      String::from("hi"),
      String::from("from"),
      String::from("the"),
      String::from("thread"),
    ];
    
    for val in vals {
      tx.send(val).unwrap();
      thread::sleep(Duration::from_millis(1));
    }  
  });
  
  for received in rx {
    println!("Got: {}", received);
  }
}

通過克隆創建多個發送者

use std::sync::mpsc;
use std::thread;
use std::time::Duration;

fn main() {
  let (tx, rx) = mpsc::channel();
  
  let tx1 = mpsc::Sender::clone(&tx);
  thread::spawn(move || {
    let vals = vec![
      String::from("1: hi"),
      String::from("1: from"),
      String::from("1: the"),
      String::from("1: thread"),
    ];
    
    for val in vals {
      tx1.send(val).unwrap();
      thread::sleep(Duration::from_millis(1));
    }  
  });
   thread::spawn(move || {
    let vals = vec![
      String::from("hi"),
      String::from("from"),
      String::from("the"),
      String::from("thread"),
    ];
    
    for val in vals {
      tx.send(val).unwrap();
      thread::sleep(Duration::from_millis(1));
    }  
  });
  
  for received in rx {
    println!("Got: {}", received);
  }
}

三、共享狀態的并發

使用共享來實作并發

  • Go 語言的名言:不要用共享記憶體來通信,要用通信來共享記憶體,
  • Rust支持通過共享狀態來實作并發,
  • Channel 類似單所有權:一旦將值的所有權轉移至 Channel,就無法使用它了
  • 共享記憶體并發類似多所有權:多個執行緒可以同時訪問同一塊記憶體

使用 Mutex 來每次只允許一個執行緒來訪問資料

  • Mutex 是 mutual exclusion(互斥鎖)的簡寫
  • 在同一時刻,Mutex 只允許一個執行緒來訪問某些資料
  • 想要訪問資料:
    • 執行緒必須首先獲取互斥鎖(lock)
      • lock 資料結構是 mutex 的一部分,它能跟蹤誰對資料擁有獨占訪問權
    • mutex 通常被描述為:通過鎖定系統來保護它所持有的資料

Mutex 的兩條規則

  • 在使用資料之前,必須嘗試獲取鎖(lock),
  • 使用完 mutex 所保護的資料,必須對資料進行解鎖,以便其它執行緒可以獲取鎖,

Mutex<T> 的 API

  • 通過 Mutex::new(資料) 來創建 Mutex<T>
    • Mutex<T>是一個智能指標
  • 訪問資料前,通過 lock 方法來獲取鎖
    • 會阻塞當前執行緒
    • lock 可能會失敗
    • 回傳的是 MutexGuard(智能指標,實作了 Deref 和 Drop)
use std::sync::Mutex;

fn main() {
  let m = Mutex::new(5);
  
  {
    let mut num = m.lock().unwrap();
    *num = 6;
  }
  
  println!("m = {:?}", m);
}

多執行緒共享 Mutex<T>

use std::sync::Mutex;
use std::thread;

fn main() {
  let counter = Mutex::new(0);
  let mut handles = vec![];
  
  for _ in 0..10 {
     let handle = thread::spawn(move || {  // 報錯 回圈 所有權
       let mut num = counter.lock().unwrap();
       
       *num += 1;
    });
    handles.push(handle);
  }
  
  for handle in handles {
    handle.join().unwrap();
  }
  
  println!("Result: {}", *counter.lock().unwrap());
}

多執行緒的多重所有權

use std::sync::Mutex;
use std::thread;
use std::rc::Rc;

fn main() {
  let counter = Rc::new(Mutex::new(0));
  let mut handles = vec![];
  
  for _ in 0..10 {
    let counter = Rc::clone(&counter);
    let handle = thread::spawn(move || {  // 報錯 rc 只能用于單執行緒
       let mut num = counter.lock().unwrap();
       
       *num += 1;
    });
    handles.push(handle);
  }
  
  for handle in handles {
    handle.join().unwrap();
  }
  
  println!("Result: {}", *counter.lock().unwrap());
}

使用 Arc<T>來進行原子參考計數

  • Arc<T>Rc<T>類似,它可以用于并發情景
    • A:atomic,原子的
  • 為什么所有的基礎型別都不是原子的,為什么標準庫型別不默認使用 Arc<T>
    • 需要性能作為代價
  • Arc<T>Rc<T> 的API是相同的
use std::sync::{Mutex, Arc};
use std::thread;

fn main() {
  let counter = Arc::new(Mutex::new(0));
  let mut handles = vec![];
  
  for _ in 0..10 {
    let counter = Arc::clone(&counter);
    let handle = thread::spawn(move || {  
       let mut num = counter.lock().unwrap();
       
       *num += 1;
    });
    handles.push(handle);
  }
  
  for handle in handles {
    handle.join().unwrap();
  }
  
  println!("Result: {}", *counter.lock().unwrap());
}

RefCell<T>/Rc<T> vs Muter<T>/Arc<T>

  • Mutex<T>提供了內部可變性,和 Cell 家族一樣
  • 我們使用 RefCell<T>來改變 Rc<T>里面的內容
  • 我們使用 Mutex<T> 來改變 Arc<T> 里面的內容
  • 注意:Mutex<T> 有死鎖風險

四、通過 Send 和 Sync Trait 來擴展并發

Send 和 Sync trait

  • Rust 語言的并發特性較少,目前講的并發特性都來自標準庫(而不是語言本身)
  • 無需局限于標準庫的并發,可以自己實作并發
  • 但在Rust語言中有兩個并發概念:
    • std::marker::Sync 和 std::marker::Send 這兩個trait

Send:允許執行緒間轉移所有權

  • 實作 Send trait 的型別可在執行緒間轉移所有權
  • Rust中幾乎所有的型別都實作了 Send
    • Rc<T> 沒有實作 Send,它只用于單執行緒情景
  • 任何完全由Send 型別組成的型別也被標記為 Send
  • 除了原始指標之外,幾乎所有的基礎型別都是 Send

Sync:允許從多執行緒訪問

  • 實作Sync的型別可以安全的被多個執行緒參考
  • 也就是說:如果T是Sync,那么 &T 就是 Send
    • 參考可以被安全的送往另一個執行緒
  • 基礎型別都是 Sync
  • 完全由 Sync 型別組成的型別也是 Sync
    • 但,Rc<T>不是 Sync 的
    • RefCell<T>Cell<T>家族也不是 Sync的
    • 而,Mutex<T>是Sync的

手動來實作 Send 和 Sync 是不安全的

本文來自博客園,作者:QIAOPENGJUN,轉載請注明原文鏈接:https://www.cnblogs.com/QiaoPengjun/p/17332132.html

轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/550524.html

標籤:其他

上一篇:推排序 Verilog實作原理

下一篇:組織樹查詢-Jvava實作(遞回)

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • 【C++】Microsoft C++、C 和匯編程式檔案

    ......

    uj5u.com 2020-09-10 00:57:23 more
  • 例外宣告

    相比于斷言適用于排除邏輯上不可能存在的狀態,例外通常是用于邏輯上可能發生的錯誤。 例外宣告 Item 1:當函式不可能拋出例外或不能接受拋出例外時,使用noexcept 理由 如果不打算拋出例外的話,程式就會認為無法處理這種錯誤,并且應當盡早終止,如此可以有效地阻止例外的傳播與擴散。 示例 //不可 ......

    uj5u.com 2020-09-10 00:57:27 more
  • Codeforces 1400E Clear the Multiset(貪心 + 分治)

    鏈接:https://codeforces.com/problemset/problem/1400/E 來源:Codeforces 思路:給你一個陣列,現在你可以進行兩種操作,操作1:將一段沒有 0 的區間進行減一的操作,操作2:將 i 位置上的元素歸零。最終問:將這個陣列的全部元素歸零后操作的最少 ......

    uj5u.com 2020-09-10 00:57:30 more
  • UVA11610 【Reverse Prime】

    本人看到此題沒有翻譯,就附帶了一個自己的翻譯版本 思考 這一題,它的第一個要求是找出所有 $7$ 位反向質數及其質因數的個數。 我們應該需要質數篩篩選1~$10^{7}$的所有數,這里就不慢慢介紹了。但是,重讀題,我們突然發現反向質數都是 $7$ 位,而將它反過來后的數字卻是 $6$ 位數,這就說明 ......

    uj5u.com 2020-09-10 00:57:36 more
  • 統計區間素數數量

    1 #pragma GCC optimize(2) 2 #include <bits/stdc++.h> 3 using namespace std; 4 bool isprime[1000000010]; 5 vector<int> prime; 6 inline int getlist(int ......

    uj5u.com 2020-09-10 00:57:47 more
  • C/C++編程筆記:C++中的 const 變數詳解,教你正確認識const用法

    1、C中的const 1、區域const變數存放在堆疊區中,會分配記憶體(也就是說可以通過地址間接修改變數的值)。測驗代碼如下: 運行結果: 2、全域const變數存放在只讀資料段(不能通過地址修改,會發生寫入錯誤), 默認為外部聯編,可以給其他源檔案使用(需要用extern關鍵字修飾) 運行結果: ......

    uj5u.com 2020-09-10 00:58:04 more
  • 【C++犯錯記錄】VS2019 MFC添加資源不懂如何修改資源宏ID

    1. 首先在資源視圖中,添加資源 2. 點擊新添加的資源,復制自動生成的ID 3. 在解決方案資源管理器中找到Resource.h檔案,編輯,使用整個專案搜索和替換的方式快速替換 宏宣告 4. Ctrl+Shift+F 全域搜索,點擊查找全部,然后逐個替換 5. 為什么使用搜索替換而不使用屬性視窗直 ......

    uj5u.com 2020-09-10 00:59:11 more
  • 【C++犯錯記錄】VS2019 MFC不懂的批量添加資源

    1. 打開資源頭檔案Resource.h,在其中預先定義好宏 ID(不清楚其實ID值應該設定多少,可以先新建一個相同的資源項,再在這個資源的ID值的基礎上遞增即可) 2. 在資源視圖中選中專案資源,按F7編輯資源檔案,按 ID 型別 相對路徑的形式添加 資源。(別忘了先把檔案拷貝到專案中的res檔案 ......

    uj5u.com 2020-09-10 01:00:19 more
  • C/C++編程筆記:關于C++的參考型別,專供新手入門使用

    今天要講的是C++中我最喜歡的一個用法——參考,也叫別名。 參考就是給一個變數名取一個變數名,方便我們間接地使用這個變數。我們可以給一個變數創建N個參考,這N + 1個變數共享了同一塊記憶體區域。(參考型別的變數會占用記憶體空間,占用的記憶體空間的大小和指標型別的大小是相同的。雖然參考是一個物件的別名,但 ......

    uj5u.com 2020-09-10 01:00:22 more
  • 【C/C++編程筆記】從頭開始學習C ++:初學者完整指南

    眾所周知,C ++的學習曲線陡峭,但是花時間學習這種語言將為您的職業帶來奇跡,并使您與其他開發人員區分開。您會更輕松地學習新語言,形成真正的解決問題的技能,并在編程的基礎上打下堅實的基礎。 C ++將幫助您養成良好的編程習慣(即清晰一致的編碼風格,在撰寫代碼時注釋代碼,并限制類內部的可見性),并且由 ......

    uj5u.com 2020-09-10 01:00:41 more
最新发布
  • Rust中的智能指標:Box<T> Rc<T> Arc<T> Cell<T> RefCell<T> Weak

    Rust中的智能指標是什么 智能指標(smart pointers)是一類資料結構,是擁有資料所有權和額外功能的指標。是指標的進一步發展 指標(pointer)是一個包含記憶體地址的變數的通用概念。這個地址參考,或 ” 指向”(points at)一些其 他資料 。參考以 & 符號為標志并借用了他們所 ......

    uj5u.com 2023-04-20 07:24:10 more
  • Java的值傳遞和參考傳遞

    值傳遞不會改變本身,參考傳遞(如果傳遞的值需要實體化到堆里)如果發生修改了會改變本身。 1.基本資料型別都是值傳遞 package com.example.basic; public class Test { public static void main(String[] args) { int ......

    uj5u.com 2023-04-20 07:24:04 more
  • [2]SpinalHDL教程——Scala簡單入門

    第一個 Scala 程式 shell里面輸入 $ scala scala> 1 + 1 res0: Int = 2 scala> println("Hello World!") Hello World! 檔案形式 object HelloWorld { /* 這是我的第一個 Scala 程式 * 以 ......

    uj5u.com 2023-04-20 07:23:58 more
  • 理解函式指標和回呼函式

    理解 函式指標 指向函式的指標。比如: 理解函式指標的偽代碼 void (*p)(int type, char *data); // 定義一個函式指標p void func(int type, char *data); // 宣告一個函式func p = func; // 將指標p指向函式func ......

    uj5u.com 2023-04-20 07:23:52 more
  • Django筆記二十五之資料庫函式之日期函式

    本文首發于公眾號:Hunter后端 原文鏈接:Django筆記二十五之資料庫函式之日期函式 日期函式主要介紹兩個大類,Extract() 和 Trunc() Extract() 函式作用是提取日期,比如我們可以提取一個日期欄位的年份,月份,日等資料 Trunc() 的作用則是截取,比如 2022-0 ......

    uj5u.com 2023-04-20 07:23:45 more
  • 一天吃透JVM面試八股文

    什么是JVM? JVM,全稱Java Virtual Machine(Java虛擬機),是通過在實際的計算機上仿真模擬各種計算機功能來實作的。由一套位元組碼指令集、一組暫存器、一個堆疊、一個垃圾回收堆和一個存盤方法域等組成。JVM屏蔽了與作業系統平臺相關的資訊,使得Java程式只需要生成在Java虛擬機 ......

    uj5u.com 2023-04-20 07:23:31 more
  • 使用Java接入小程式訂閱訊息!

    更新完微信服務號的模板訊息之后,我又趕緊把微信小程式的訂閱訊息給實作了!之前我一直以為微信小程式也是要企業才能申請,沒想到小程式個人就能申請。 訊息推送平臺🔥推送下發【郵件】【短信】【微信服務號】【微信小程式】【企業微信】【釘釘】等訊息型別。 https://gitee.com/zhongfuch ......

    uj5u.com 2023-04-20 07:22:59 more
  • java -- 緩沖流、轉換流、序列化流

    緩沖流 緩沖流, 也叫高效流, 按照資料型別分類: 位元組緩沖流:BufferedInputStream,BufferedOutputStream 字符緩沖流:BufferedReader,BufferedWriter 緩沖流的基本原理,是在創建流物件時,會創建一個內置的默認大小的緩沖區陣列,通過緩沖 ......

    uj5u.com 2023-04-20 07:22:49 more
  • Java-SpringBoot-Range請求頭設定實作視頻分段傳輸

    老實說,人太懶了,現在基本都不喜歡寫筆記了,但是網上有關Range請求頭的文章都太水了 下面是抄的一段StackOverflow的代碼...自己大修改過的,寫的注釋挺全的,應該直接看得懂,就不解釋了 寫的不好...只是希望能給視頻網站開發的新手一點點幫助吧. 業務場景:視頻分段傳輸、視頻多段傳輸(理 ......

    uj5u.com 2023-04-20 07:22:42 more
  • Windows 10開發教程_編程入門自學教程_菜鳥教程-免費教程分享

    教程簡介 Windows 10開發入門教程 - 從簡單的步驟了解Windows 10開發,從基本到高級概念,包括簡介,UWP,第一個應用程式,商店,XAML控制元件,資料系結,XAML性能,自適應設計,自適應UI,自適應代碼,檔案管理,SQLite資料庫,應用程式到應用程式通信,應用程式本地化,應用程式 ......

    uj5u.com 2023-04-20 07:22:35 more