Zum Hauptinhalt springen
tsecurity.de LIVE
Echtzeit-Radar & Feeds
Alle RSS Feeds ➔
👥 Community & Social
IT Security ToolsGitHub Release: google/clusterfuzz v2.41.2 (24.09.2026)(24.09.2026 um 14:57 Uhr)
•
IT Security NachrichtenNew Browser Guard features add protection before and after you click(24.09.2026 um 14:45 Uhr)
•
IT Security NachrichtenMeta brings Private Processing privacy protections to AI glasses(24.09.2026 um 14:44 Uhr)
•••••
IT Security NachrichtenTesla FSD Fails Belgian Safety Tests(24.09.2026 um 14:56 Uhr)
•
Sicherheitslücken (CVE)CISA Charts New "Quality Era" for Global CVE Program(24.09.2026 um 14:50 Uhr)
•
IT Security NachrichtenThe cost of intelligence?(24.09.2026 um 15:00 Uhr)
•
IT Security ToolsGitHub Release: google/clusterfuzz v2.41.2 (24.09.2026)(24.09.2026 um 14:57 Uhr)
•
IT Security NachrichtenNew Browser Guard features add protection before and after you click(24.09.2026 um 14:45 Uhr)
•
IT Security NachrichtenMeta brings Private Processing privacy protections to AI glasses(24.09.2026 um 14:44 Uhr)
•••••
IT Security NachrichtenTesla FSD Fails Belgian Safety Tests(24.09.2026 um 14:56 Uhr)
•
Sicherheitslücken (CVE)CISA Charts New "Quality Era" for Global CVE Program(24.09.2026 um 14:50 Uhr)
•
IT Security NachrichtenThe cost of intelligence?(24.09.2026 um 15:00 Uhr)
•
Intelligence View
⚡ tsecurity.de Intelligence

Building a dead simple background job in Rust

In today's post we'll explore how to create a basic background job in Rust, simulating Rust channels with a Vector-based queue. First things first Generally, a background job operates on one or more threads that continuously…

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!

In today's post we'll explore how to create a basic background job in Rust, simulating Rust channels with a Vector-based queue.









First things first



Generally, a background job operates on one or more threads that continuously consume messages from a queue.



In this post, we'll use a Vector to represent our queue.



This Vector is an instance of the standard Rust library implementation known as VecDeque. VecDeque is a double-ended queue that acts as a growing ring buffer.






Data model



To make our solution more organized, we can define 3 structs:






Transmitter



The transmitter (tx) holds an store, which is the queue (Vector) encapsulated by a Arc/Mutex; and an emitter, which is a Condvar, used for synchronization based on a condition.






Receiver



The receiver (rx), pretty much like the transmitter, also holds a store and an emitter.






Channel



Channel holds a transmitter and a receiver.




struct Transmitter<T> {
store: Arc<Mutex<VecDeque<T>>>,
emitter: Arc<Condvar>,
}

struct Receiver<T> {
store: Arc<Mutex<VecDeque<T>>>,
emitter: Arc<Condvar>,
}

struct Channel<T> {
tx: Transmitter<T>,
rx: Receiver<T>,
}









What is an Arc in Rust?



The queue (VecDeque) is going to be shared across the channel for one or more threads.



In Rust, such problem requires shared ownership addressed by a reference counter (Rc), but since we are in a multi-thread scenario, Rc is not thread-safe, that's why we need an atomic reference counter, or simply Arc, which is indeed thread-safe.




You can learn more details about smart pointers by reading my post on Understanding the basics of smart pointers in Rust







How about Mutex?



Since Arc is a reference counter, its references are immutable. For mutability in the underlying data, we need interior mutability using RefCell.




My mentioned post about smart pointers also covers interior mutability, check it out for further details




In the same as Rc, RefCell is not thread-safe. For a thread-safe scenario, we need to synchronize access to data using locks. That's where mutual exclusion (Mutex) comes in.






Okay, and Condvar? What the heck is that?



Condvar is a primitive for synchronization in concurrent systems where we can put a thread to "wait" (suspended) until a given condition is met.



For blocking queues, we basically want the following condition (pseudo-code):




queue = some_array
mutex = os_lock
emitter = os_condvar

// Thread is suspened until the array gets some data
// There's no CPU consume
while queue is empty
emitter.wait(mutex)
end

// Someone emitted a signal
data = queue.pop






In other process:




queue.push(data)
emitter.signal









Data modeling implementation



Now, let's implement the methods send and recv (receive) in our simulated channel.






Transmitter



The transmitter (tx) will have a method called send, which basically:




  • locks the shared queue (store.lock().unwrap())

  • pushes data to the queue (push_back(data))

  • emits a signal (emitter.notify_one) to notify some suspended thread that is waiting for data in the queue




impl<T> Transmitter<T> {
fn send(&self, data: T) {
self.store.lock().unwrap().push_back(data);
self.emitter.notify_one();
}
}









Receiver



The receiver (rx) has a method called recv (short for receive) which:




  • creates a lock in the shared queue (store.lock().unwrap())

  • suspends the current thread until the condition is met, in other words, while the queue is empty, the thread is suspended in the operating system, thus not consuming CPU (emitter.wait)

  • once the thread is awaken, it can pops the data from the queue (store.pop_front())




impl<T> Receiver<T> {
fn recv(&self) -> Option<T> {
let mut store = self.store.lock().unwrap();

while store.is_empty() {
store = self.emitter.wait(store).unwrap();
}

store.pop_front()
}
}






Moreover, the Receiver struct can have an extra method called try_recv which does not block the thread, not using the Condvar condition:




fn try_recv(&self) -> Option<T> {
self.store.lock().unwrap().pop_front()
}









Channel



Once the Transmitter and Receiver are already implemented, the implementation of Channel is a piece of cake:




impl<T> Channel<T> {
fn new() -> Self {
let store = Arc::new(Mutex::new(VecDeque::new()));
let emitter = Arc::new(Condvar::new());

Channel {
tx: Transmitter { store: Arc::clone(&store), emitter: Arc::clone(&emitter) },
rx: Receiver { store: Arc::clone(&store), emitter: Arc::clone(&emitter) },
}
}
}






Note that both Mutex and Condvar are encapsulated in an Arc (atomic reference counter), because we have to share them across tx and rx at the same time.






Main



The main function can me implemented as follows:




  • create a channel and binds the tx and rx respectively

  • the channel holds a shared Mutex/VecDeque and a Condvar

  • tx is used to send data to the channel

  • rx is used from the inner thread to receive data from the channel




fn main() {
// Initialize channel
let channel = Channel::new();
let (tx, rx) = (channel.tx, channel.rx);

// Push data to the channel
tx.send("Some job to do: 1");
tx.send("Another job: 2");

// Process the channel
let worker = thread::spawn(move || {
loop {
let job = rx.recv(); // we could use try_recv too

match job {
Some(job) => println!("Job: {}", job),
None => break,
}
}
});

// Push more data to the channel
tx.send("Yet another job");

worker.join().unwrap();
}






We run the code and, Yay, everything is working as expected:




Job: Some job to do: 1
Job: Another job: 2
Job: Yet another job












Rust channels for the rescue



You may be wondering:




Hey Leandro, why doesn't Rust bring all this stuff already built-in? Do we really need to implement a raw queue and use synchronization primitives on our own every time we want to create a channel for threads?




Today is your lucky day. Indeed Rust brings Channels, which employ the same techniques described in this very post, but more robust, of course:




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

fn main() {
// Initialize channel
let (tx, rx) = mpsc::channel();

// Push data to the channel
tx.send("Some job to do: 1").unwrap();
tx.send("Another job: 2").unwrap();

let worker = thread::spawn(move || {
loop {
let job = rx.recv();

match job {
Ok(job) => println!("Job: {}", job),
Err(_) => break,
}
}
});

// Push more data to the channel
tx.send("Yet another job").unwrap();

worker.join().unwrap();
}








  • mpsc stands for multiple producers, single consumer


  • mpsc::channel creates a channel with a internal shared queue and returns a transmitter (tx) and a receiver (rx)

  • pretty much like our custom implementation, tx.send sends data to the channel, whereas tx.recv reads/pops data from the channel



How cool is that?









References



https://doc.rust-lang.org/book/ch16-00-concurrency.html



https://doc.rust-lang.org/std/vec/struct.Vec.html



https://doc.rust-lang.org/std/collections/struct.VecDeque.html



https://dev.to/leandronsp/understanding-the-basics-of-smart-pointers-in-rust-3dff

IoC Intelligence (1 Indikatoren)
dev[.]to
CTI Threat Relationship Graph3 Knoten / 2 Relationen
CVE / Incident Software MITRE ATT&CK CWE Weakness IoC
SOC Incident Playbook: Vulnerability Remediation & Verification
title: Detect Exploitation - Building a dead simple background job in Rust
id: 8b39d63e-24b4-48aa-9621-d5bcf6639b52
status: experimental
description: Automatisch generierte SIEM-Erkennungsregel basierend auf CTI Intelligence
references:
  - https://tsecurity.de/
author: iShareStuff CTI Automated Detection Engine
date: 2026-09-24
logsource:
  category: network_connection
  product: any
detection:
  selection:
      DestinationHostname:
        - 'dev.to'
  condition: selection
falsepositives:
  - Legitime administrative Zugriffe oder Penetrationstests
level: high
tags:
  - attack.initial_access
rule CTI_Threat_Indicator {
    meta:
        author = "iShareStuff CTI Automated Detection Engine"
        date = "2026-09-24"
        description = "YARA Signature for "
    strings:
        $str = "Building a dead simple backgro" ascii wide
    condition:
        any of them
}
tsecurity.de Cognitive Threat RAG
Fokus-Vektor:

Kognitive Analyse für identifizierte Bedrohung: Erhöhte Bedrohungslage im Bereich Building a dead simple background job in.... Basierend auf 368k Vektor-Korrelationen werden sofortige Isolationsmaßnahmen für betroffene Endpunkte empfohlen.

🛡️ Angriffsfläche & Exposure

Netzwerk/Remote-Zugriff ohne Vorauthentifizierung möglich.

⚡ Empfohlene Sofortmaßnahmen
  • 1. Perimeter-Inspektion: Relevante Portfreigaben und exponierte Endpunkte unverzüglich scannen.
  • 2. Patch-Applikation: Hersteller-Hotfix einspielen oder betroffene Daemons in isolierte DMZ-Segmente überführen.
  • 3. Telemetrie & EDR-Alerts: Prozessaufrufe und Child-Processes auf anomale Shell-Spawns überwachen.
🔗 Semantisch verwandte Zero-Days MariaDB 11.7 VEC
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Building a dead simple background job in Rust

Thematisch verwandte Begriffe: Building, dead, simple, background · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-97152 | Nanomsg versions 0.5-beta through 1.x before 1.2.3 has a remotely exploi…
Advisory →
TTS Reader • tsecurity.de Voice
tsecurity.de Icon
tsecurity.de App
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag
Themen-Radar & Intelligence Matrix
Echtzeit-Taxonomie nach Angriffsvektoren & Plattformen

tsecurity.de Live Threat Radar

🔴 LIVE RADAR
MONITORING
AKTIV
CVE-DATENBANK
LIVE
🔍
Community Radar & Live Chat
Sentinel Bot online • Live-Stream
Dein Cluster: Security Explorer
Match:
lädt…
Verbindung zum Community-Stream wird aufgebaut...
Bearbeitungsmodus — Senden überschreibt deine Nachricht
Community-Puls — was gerade passiert
lädt…
Aktivitäten deiner Analysten
lädt…
Neues Thema oder Eilmeldung einreichen

Reiche interessante Links, Zero-Days oder Debatten ein. Die Community entscheidet per Upvote über die Veröffentlichung.

Heiß diskutierte Einreichungen
🔖 Gespeicherte Artikel
📂 Keine gespeicherten Artikel vorhanden.
Zurück Ziehen Vor
Links: vorheriger Artikel • Rechts: nächster Artikel • unten: schließen
News NIS-2 Frühwarnung Tier-1 Intel TTP ⏱️ 3 Min vor 10 Min
Artikeldaten werden geladen...

Zurück: vorheriger • Vor: nächster
↗ Original-Quelle
Social Reaktionen Deine Reaktion zählt
Einstufung & Relevanz-Poll 0 Stimmen
In sozialen Netzwerken teilen 1-Klick