Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change DYNAMIC_THREAD_COUNT to be an AtomicUsize #451

Closed
wants to merge 9 commits into from
6 changes: 3 additions & 3 deletions src/task/spawn_blocking.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::sync::atomic::{AtomicU64, Ordering};
use std::sync::atomic::{AtomicUsize, Ordering};
use std::thread;
use std::time::Duration;

Expand Down Expand Up @@ -49,9 +49,9 @@ where
JoinHandle::new(handle)
}

const MAX_THREADS: u64 = 10_000;
const MAX_THREADS: usize = 10_000;

static DYNAMIC_THREAD_COUNT: AtomicU64 = AtomicU64::new(0);
static DYNAMIC_THREAD_COUNT: AtomicUsize = AtomicUsize::new(0);

struct Pool {
sender: Sender<Runnable>,
Expand Down
8 changes: 4 additions & 4 deletions src/task/task_id.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::fmt;
use std::sync::atomic::{AtomicU64, Ordering};
use std::sync::atomic::{AtomicUsize, Ordering};

/// A unique identifier for a task.
///
Expand All @@ -13,15 +13,15 @@ use std::sync::atomic::{AtomicU64, Ordering};
/// })
/// ```
#[derive(Eq, PartialEq, Clone, Copy, Hash, Debug)]
pub struct TaskId(pub(crate) u64);
pub struct TaskId(pub(crate) usize);

impl TaskId {
/// Generates a new `TaskId`.
pub(crate) fn generate() -> TaskId {
static COUNTER: AtomicU64 = AtomicU64::new(1);
static COUNTER: AtomicUsize = AtomicUsize::new(1);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should still be an AtomicU64, I'm afraid. What we can do is use AtomicCell<u64> from crossbeam-utils.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have changed it as you suggest


let id = COUNTER.fetch_add(1, Ordering::Relaxed);
if id > u64::max_value() / 2 {
if id > usize::max_value() / 2 {
std::process::abort();
}
TaskId(id)
Expand Down