-
Notifications
You must be signed in to change notification settings - Fork 124
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
Command delayed when sent from another thread #646
Comments
Could you give some details about what you are doing? In particular what is being done on which thread? |
The main thread runs the main dispatch loop, fn main() {
let mut layout_manager = LayoutManager::default();
let conn = Connection::connect_to_env().unwrap();
let mut event_queue = conn.new_event_queue();
// `get_registry` has necessary side-effects.
let _registry = conn.display().get_registry(&event_queue.handle(), ());
event_queue.roundtrip(&mut layout_manager).unwrap();
loop {
event_queue.blocking_dispatch(&mut layout_manager).unwrap();
}
} and everything not handled by the other thread. The other thread is sometimes spawned during a let control = Arc::clone(
state
.control
.as_ref()
.expect("River control should be initialized"),
);
let seat = Arc::clone(
state.seat.as_ref().expect("seat should be initialized"),
);
let qhandle = qhandle.clone();
thread::spawn(move || {
let layout = layout(usable_width, usable_height, view_count);
CACHE.lock().unwrap().insert(key, layout);
// River will send a new layout demand
// if it receives a layout command.
let control = control.lock().unwrap();
control.add_argument("send-layout-cmd".to_owned());
control.add_argument("owm".to_owned());
control.add_argument("retry-layout".to_owned());
control.run_command(&seat, &qhandle, ());
}); |
I guess the issue is that you need to flush the connection? |
Could you put |
|
Ah, yeah, it's on the queue itself. You could |
That worked. Although, the question remains, why do I need to flush the connection when sending from another thread? |
Because when you do |
I see. Perhaps this should be documented more prominently? Maybe a section on multithreading in the |
Well, the |
However, a user is unlikely to look for the |
I mean, I don't deny that more obvious docs could be better, it's up to @elinorbgr in the end. |
Noted, we can improve the toplevel docs to make the need for flushing more obvious. |
Using
run_command
from theriver-control
protocol, https://github.com/riverwm/river/blob/c16628c7f57c51d50f2d10a96c265fb0afaddb02/protocol/river-control-unstable-v1.xml, worked as expected when my application was single-threaded. The command was dispatched and my application received the resulting callback and Riverlayout_demand
immediately. However, when I moved therun_command
code to a separate thread, I noticed odd behavior. The callback andlayout_demand
would only be received after another event was received in the same queue, as if the other event flushed the queue. As far as I can tell, it was the command being dispatched that was delayed, not the callback being received, because thelayout_demand
from River that should follow the command was also delayed.The text was updated successfully, but these errors were encountered: