並行処理の実装パターン #197
ubnt-intrepid
started this conversation in
General
並行処理の実装パターン
#197
Replies: 1 comment
-
1. single-threadedfn main() -> anyhow::Result<()> {
let (devfd, mount) = mount("/path/to/mountpoint", MountOptions::default())?;
let mut conn = Connection::from(devfd);
let session = Session::init(&mut conn, KernelConfig::default())?;
let mut req = session.new_request_buffer()?;
while session.read_request(&mut conn, &mut req)? {
match req.operation()? {
Operation::Lookup(op) => do_lookup(...)?,
_ => session.reply_error(&mut conn, &req, libc::ENOSYS)?,
}
}
mount.unmount()?;
Ok(())
} 2. per worker threadfn main() -> anyhow::Result<()> {
let (conn, session) = /* ...omit... */;
std::thread::scope(|scope| -> anyhow::Result<()> {
for i in ..num_worker_threads {
let session = &session;
let mut conn = conn.try_ioc_clone()?;
let mut req = session.new_request_buffer()?;
scope.spawn(|| {
while session.read_request(&mut conn, &mut req)? {
match req.operation()? {
Operation::Lookup(op) => do_lookup(...)?,
_ => session.reply_error(&mut conn, &req, libc::ENOSYS)?,
}
});
}
Ok(())
})?;
mount.unmount()?;
Ok(())
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
今後のAPI開発を見据え、FUSE 特有の並行処理の実装パターンを整理しておきたい。
あくまで思考整理のためであり、実際に有効なデザインパターンなのかどうかは考えずにいきたい。
Beta Was this translation helpful? Give feedback.
All reactions