<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Sep 17, 2015 at 4:54 PM, Marc-André Lureau <span dir="ltr"><<a href="mailto:mlureau@redhat.com" target="_blank">mlureau@redhat.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class=""><br>
<br>
----- Original Message -----<br>
<br>
> > > Sorry I didn't mean what the thread was doing, but rather why we need a<br>
> > > thread for this task.<br>
> ><br>
> > Well I could use a g_task or g_idle, or something like that, but g_idle<br>
> > isn't<br>
> > cancellable, and g_task<br>
><br>
> g_idle is cancellable.<br>
><br>
> Hmm, I couldn't find in the documentation. Usually the functions have some<br>
> kind of GCancellable parameter.<br>
<br>
</span>You can do g_source_remove(), no need for cancellable<br></blockquote><div><br></div><div>Ah, ok.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<span class=""><br>
> It's hardly convincing me, threads are more racy by nature.<br>
><br>
> That's true, but since I just need a few lines of code in the thread, and<br>
> it's not<br>
> accessing anything externally (other then the cancel), the thread API is<br>
> simpler for what I need.<br>
><br>
> With glib functions (g_task, g_idle, GSimplaAsyncResult), I need to supply<br>
> stuff<br>
> I either don't need, or I don't know what they're for. I just need something,<br>
> that will<br>
> call a function after 5 seconds, and can be cancelled.<br>
> That's 2-3 parameters (callback, cancel, maybe time).<br>
><br>
> Since I don't have that much experience with GLibs Async functions, I chose a<br>
> thread.<br>
> For me it's simpler to implement and to test, it's fewer lines of code, and<br>
> since the function<br>
> it runs is simple, I don't think that there is any advantage in using<br>
> something else.<br>
> More so, if the other functions spawn a thread internally anyway.<br>
><br>
> I tried using a timer, and removing it before it fired, but sometimes it<br>
> fired, even when it wasn't supposed to.<br>
> I could pass a GCancellable to the timeout instead, and let it fire, but then<br>
> I would have multiple timeouts<br>
> firing at the same time, for no reason (because I would cancel the<br>
> cancellable).<br>
><br>
<br>
</span>not clear to me, but ok<br>
<span class=""><br>
><br>
><br>
> Trying to read from the driver when the started is wrong, at least it should<br>
> be after the virtio and the listening socket have been successfully opened.<br>
><br>
> Well I'm not actually reading anything. And I think that read_thread starts<br>
> only after<br>
> everything is prepared, because If I start the service with sharing enabled,<br>
> everything works fine.<br>
> If the user is not connected/sharing is not enabled, the only thing my<br>
> patches do, is that the new thread<br>
> waits for a few seconds, and gets cancelled, when the main loop ends (which<br>
> will happen almost immediately).<br>
<br>
</span>Yes, so you could start it after the service is actually started and the virtio port is opened, no? (repeating myself here)<br></blockquote><div><br></div><div>Ah you mean socket_service? I thought you meant the windos service.<br>Yeah I can move it just above start_mux_read (mux_istream);<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<span class=""><br>
><br>
> I can imagine it may block because WNetAddConnection2 function call is sync<br>
> and will probe the service. But if it's blocking then it will not be able to<br>
> handle its communication work.<br>
><br>
> Why not wrap WNetAddConnection2 in a GSimplaAsyncThread and run it once the<br>
> client connection is established?<br>
><br>
> Well that's the problem. I don't know when the client is connected, because<br>
> there is no signal/callback,<br>
> anything that would notify me, that the client connected. The only way I<br>
> know, that the client is connected,<br>
> is that the service stops looping, because it blocked in read_thread (this<br>
> was happening before my patches also).<br>
><br>
<br>
> When it blocks, I have no way to call anything, that would map the drive, or<br>
> notify something to map the drive.<br>
<br>
</span>read_async is.. async! the thread is a helper, the mainloop is free for other events/task.<br></blockquote><div><br></div><div>But read_async is not the issue, read_thread is.<br>g_input_stream_read_all() is not async, so it blocks when there are no data. It only receives data, after:<br></div><div>1. client connects<br></div><div>2. enables sharing<br></div><div>3. maps the drive<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<span class=""><br>
> That's why the only way was to start something before the read blocked, wait<br>
> for a few seconds, and if nothing<br>
> told it otherwise, it would map the drive. If the read didn't block, it would<br>
> somehow notify this something,<br>
> that the client is not actually connected, and not to map the drive.<br>
><br>
> I spent a few weeks trying to implement something using already defined<br>
> signals, g_poll, even windows specific<br>
> polling/async reading, but nothing worked.<br>
<br>
</span>Check if the mainloop is working properly using a timer, it should be fine. Then we can realize it's blocking when you actuall call WNetAddConnection2, and then you realize it's the reason you need a thread.<br></blockquote><div><br></div><div>The mainloop should work fine, the only think that's blocked is the read_thread<br>(talking about a function called read_thread here)<br><br></div><div>I can try something else using mainloop, but just so we understand each other,<br>I still need another thread. It doesn't matter, if it's mainloop, or mine thread,<br>but it HAS to be a different thread then the one where read_thread() is working.<br>We agree on that right?<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<span class=""><br>
><br>
> The bottom line is that even when it is usually better to use something more<br>
> high level then a thread,<br>
> I think it's safe to use a thread here, and using more high level stuff<br>
> wouldn't bring any advantage.<br>
<br>
</span>My bottom line is: don't use thread if you don't need them<br>
<span class=""><br>
> When I tried implementing something other then a thread, the only thing that<br>
> brought was a headache,<br>
> because they refused to work at all.<br>
<br>
</span>That's a good sign that there is something you didn't solve properly.<br></blockquote><div><br></div><div>Yes, I'm aware of that. But since thread worked properly, I had no issue with using it.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div class=""><div class="h5"><br>
><br>
><br>
><br>
> > As for why this has to be in a different thread, then read_thread, is<br>
> > because<br>
> > if I call map_drive before<br>
> > read actually blocks, it returns error, as if it's not connected. I think<br>
> > this is because when we try to map<br>
> > the drive, client sends a message to the guest, and the read has to be<br>
> > ready<br>
> > to receive it, which in turn<br>
> > lets the map_drive to actually map the drive.<br>
> ><br>
> > I tryed using every possible way I could think of, even windows specific<br>
> > polling, but I couldn't make<br>
> > anything work, except just plain spawning another thread.<br>
> ><br>
> > Lukas Venhoda<br>
> ><br>
> > _______________________________________________<br>
> > Spice-devel mailing list<br>
> > <a href="mailto:Spice-devel@lists.freedesktop.org">Spice-devel@lists.freedesktop.org</a><br>
> > <a href="http://lists.freedesktop.org/mailman/listinfo/spice-devel" rel="noreferrer" target="_blank">http://lists.freedesktop.org/mailman/listinfo/spice-devel</a><br>
> ><br>
><br>
> Lukas Venhoda<br>
><br>
> _______________________________________________<br>
> Spice-devel mailing list<br>
> <a href="mailto:Spice-devel@lists.freedesktop.org">Spice-devel@lists.freedesktop.org</a><br>
> <a href="http://lists.freedesktop.org/mailman/listinfo/spice-devel" rel="noreferrer" target="_blank">http://lists.freedesktop.org/mailman/listinfo/spice-devel</a><br>
><br>
</div></div></blockquote></div><br>Lukas<br></div></div>