Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
L
learn-thread-rust
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nawasan Wisitsingkhon
learn-thread-rust
Commits
e87c8e7a
Commit
e87c8e7a
authored
Mar 11, 2024
by
Nawasan Wisitsingkhon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
initial commit
parents
Pipeline
#1948
failed with stages
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
123 additions
and
0 deletions
+123
-0
.gitignore
.gitignore
+1
-0
Cargo.lock
Cargo.lock
+75
-0
Cargo.toml
Cargo.toml
+9
-0
main.rs
src/main.rs
+38
-0
No files found.
.gitignore
0 → 100644
View file @
e87c8e7a
/target
Cargo.lock
0 → 100644
View file @
e87c8e7a
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "getrandom"
version = "0.2.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5"
dependencies = [
"cfg-if",
"libc",
"wasi",
]
[[package]]
name = "libc"
version = "0.2.153"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd"
[[package]]
name = "multi_thread"
version = "0.1.0"
dependencies = [
"rand",
]
[[package]]
name = "ppv-lite86"
version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
[[package]]
name = "rand"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [
"libc",
"rand_chacha",
"rand_core",
]
[[package]]
name = "rand_chacha"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
dependencies = [
"ppv-lite86",
"rand_core",
]
[[package]]
name = "rand_core"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
dependencies = [
"getrandom",
]
[[package]]
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
Cargo.toml
0 → 100644
View file @
e87c8e7a
[package]
name
=
"multi_thread"
version
=
"0.1.0"
edition
=
"2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
rand
=
"0.8.5"
src/main.rs
0 → 100644
View file @
e87c8e7a
use
rand
::{
self
,
Rng
};
use
std
::{
thread
::{
self
,
JoinHandle
},
time
::
Instant
,
};
fn
th_run
()
{
let
mut
random
=
rand
::
thread_rng
();
let
mut
arr
=
vec!
[
0u8
;
1
_000_000
];
for
_
in
0
..
100
{
for
i
in
0
..
1
_000_000
{
arr
[
i
]
=
random
.gen
();
}
}
println!
(
"th_run: end"
);
}
fn
main
()
{
let
start
=
Instant
::
now
();
// th_run();
// th_run();
let
mut
thread_list
:
Vec
<
JoinHandle
<
()
>>
=
vec!
[];
for
_
in
0
..
2
{
let
t
=
thread
::
spawn
(
move
||
{
th_run
();
});
thread_list
.push
(
t
);
}
println!
(
"count: {}"
,
thread_list
.len
());
for
th
in
thread_list
{
th
.join
()
.unwrap
();
}
println!
(
"{:?}"
,
start
.elapsed
());
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment