Crates.io | concurrency_example |
lib.rs | concurrency_example |
version | 0.1.3 |
source | src |
created_at | 2024-11-18 10:57:46.983416 |
updated_at | 2024-11-21 00:57:02.07416 |
description | A simple Rust program demonstrating concurrency using threads. |
homepage | |
repository | |
max_upload_size | |
id | 1452095 |
size | 3,204 |
This is a simple Rust program demonstrating concurrency using threads. The program spawns a new thread that runs in parallel with the main thread. Both threads print messages to the terminal, but with different sleep intervals, allowing you to observe how they execute concurrently.
The spawned thread prints a message every 500 milliseconds. The main thread prints a message every 1000 milliseconds. Once the main thread finishes, it waits for the spawned thread to complete using join().
Make sure you have Rust installed on your system. If not, download it from rust-lang.org.
cargo run
Expected Output: You should see alternating messages from the main thread and the spawned thread in your terminal:
Hi from the main thread: 1
Hi from the spawned thread: 1
Hi from the spawned thread: 2
Hi from the main thread: 2
...
This program runs in the terminal, so make sure to run it from a terminal emulator. The output might appear differently depending on your terminal's behavior with concurrent prints.
This project is licensed under the MIT License
bensatlantik