Skip to content

Commit 9ad8f2c

Browse files
committed
samples: philosophers: Convert channel sync to dynamic
Use the new dynamically allocated Channels to simplify the code. Signed-off-by: David Brown <[email protected]>
1 parent b246118 commit 9ad8f2c

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

samples/philosophers/src/channel.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,9 @@ impl ChannelSync {
112112
/// Generate a syncer out of a ChannelSync.
113113
#[allow(dead_code)]
114114
pub fn get_channel_syncer() -> Vec<Arc<dyn ForkSync>> {
115-
let command_queue = COMMAND_QUEUE.init_once(()).unwrap();
116-
let (cq_send, cq_recv) = channel::unbounded_from(command_queue);
117-
let reply_queues = REPLY_QUEUES.each_ref().map(|m| {
118-
channel::unbounded_from(m.init_once(()).unwrap())
115+
let (cq_send, cq_recv) = channel::unbounded();
116+
let reply_queues = [(); NUM_PHIL].each_ref().map(|()| {
117+
channel::unbounded()
119118
});
120119
let syncer = reply_queues.into_iter().map(|rqueue| {
121120
let item = Box::new(ChannelSync::new(cq_send.clone(), rqueue))
@@ -165,9 +164,4 @@ impl ForkSync for ChannelSync {
165164
kobj_define! {
166165
static CHANNEL_STACK: ThreadStack<2054>;
167166
static CHANNEL_THREAD: StaticThread;
168-
169-
// For communicating using Queue, there is one to the main thread (the manager), and one back
170-
// to each philosopher.
171-
static COMMAND_QUEUE: StaticQueue;
172-
static REPLY_QUEUES: [StaticQueue; NUM_PHIL];
173167
}

0 commit comments

Comments
 (0)