After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 109966 - Dispatcher does not work on win32
Dispatcher does not work on win32
Status: RESOLVED FIXED
Product: glibmm
Classification: Bindings
Component: threads
2.4.x
Other Windows
: Normal normal
: ---
Assigned To: gtkmm-forge
gtkmm-forge
Depends on:
Blocks:
 
 
Reported: 2003-04-04 11:46 UTC by Cedric Gustin
Modified: 2007-01-24 13:10 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Dispatcher win32 patch (5.89 KB, patch)
2003-04-04 11:52 UTC, Cedric Gustin
none Details | Review
Added commentaries to the patch (6.99 KB, patch)
2003-04-14 08:00 UTC, Andrew E. Makeev
none Details | Review
fixed lock for prev patch (6.90 KB, patch)
2003-04-15 08:21 UTC, Andrew E. Makeev
none Details | Review
dispatcher patch for win32 (correct a small typo) (1.11 KB, patch)
2003-05-08 13:47 UTC, Cedric Gustin
none Details | Review
fixed-up patch (10.49 KB, patch)
2004-05-20 20:53 UTC, Daniel Elstner
none Details | Review
Fixes crash of dispatcher example on win32 (2.42 KB, patch)
2004-08-10 08:20 UTC, Cedric Gustin
none Details | Review
Output of dispatcher example with neither usleep nor yield (7.41 KB, text/plain)
2007-01-24 13:09 UTC, Cedric Gustin
  Details
Output of dispatcher example with usleep (7.41 KB, text/plain)
2007-01-24 13:09 UTC, Cedric Gustin
  Details
Output of dispatcher example with yield (7.41 KB, text/plain)
2007-01-24 13:10 UTC, Cedric Gustin
  Details

Description Cedric Gustin 2003-04-04 11:46:56 UTC
Glib::Dispatcher builds fine on win32 using mingw32 but the 
examples/thread/dispatcher and dispatcher2 examples do not work.
Comment 1 Cedric Gustin 2003-04-04 11:51:48 UTC
I received a workaround a few days ago from Andrew Makeev. I somewhat 
rearranged the code and adapted it to the current CVS dispatcher.cc. 
A patch is attached. The dispatcher examples now run fine.
If somebody (Daniel ?) could have a look at it... I'm not a pipe/file 
descriptor specialist ! If it's ok, I'll add a patched ChangeLog.
Comment 2 Cedric Gustin 2003-04-04 11:52:32 UTC
Created attachment 15466 [details] [review]
Dispatcher win32 patch
Comment 3 Murray Cumming 2003-04-08 07:46:52 UTC
Platform-specific workarounds _must_ have source code comments
explaining what they do and why they are necessary.
Comment 4 Cedric Gustin 2003-04-09 05:58:02 UTC
As I said, I got this win32-specific Dispatcher from Andrew Makeev 
without any further explanation. Having no experience with pipe/file 
descriptor, I decided to just create a patch and submit it AS IS on 
bugzilla for review/comments by specialists. Maybe if Andrew or 
Daniel could comment on this...
Comment 5 Murray Cumming 2003-04-13 13:02:38 UTC
Yes, I was just making clear what needs to be done before we can
commit it. Thanks for making sure that it didn't get lost.
Comment 6 Andrew E. Makeev 2003-04-14 08:00:49 UTC
Created attachment 15696 [details] [review]
Added commentaries to the patch
Comment 7 Andrew E. Makeev 2003-04-15 08:21:00 UTC
Created attachment 15730 [details] [review]
fixed lock for prev patch
Comment 8 Murray Cumming 2003-04-16 16:54:55 UTC
Great. Even though it still doesn't mean much to me, that's a lot
better. However, I don't know what "btw" means - maybe that could be
changed?

It seems like this is ready for Daniel to look at it. Daniel?

Comment 9 Murray Cumming 2003-04-21 11:46:26 UTC
Daniel is hard to contact recently. Do tell us if you require this in
a release urgently.
Comment 10 Andrew E. Makeev 2003-04-22 05:42:46 UTC
btw = between, just common abbreviation.

The patch is needed by our Application that we are developing at the
moment, thus patching every new release before installing and building
RPM's is very annoying, you know.
Comment 11 Murray Cumming 2003-04-24 06:51:51 UTC
I have cleaned this up a bit and committed it to both branches. Please
try to conform to existing styles when patching documents. Thanks a
lot for this. Please check that it still works as expected.
Comment 12 Cedric Gustin 2003-05-08 13:46:27 UTC
The attached patch fixes a small typo in glib/glibmm/dispatcher.cc. 
Without it, the file does not compile on win32.
As a side note, examples/thread/dispatcher freezes on my machine 
(win2k + SP3). The dispatcher2 example is fine.
Comment 13 Cedric Gustin 2003-05-08 13:47:51 UTC
Created attachment 16365 [details] [review]
dispatcher patch for win32 (correct a small typo)
Comment 14 Murray Cumming 2003-05-09 17:28:45 UTC
Applied to both branches. Thanks. Actually, I thought you had cvs
write access now - feel free to commit simple stuff like this.
Comment 15 Daniel Elstner 2004-05-20 19:33:58 UTC
Reopened because parts of the new win32 code look fishy to me.  For instance,
the DispatchNotifyData objects in the queue are both read and written without
any locking at all.  Only locking the queue is not sufficient, you have to lock
the data too.

I think it'd be best to get rid of of dynamic memory allocation altogether --
there's simply no need for this.  Further, there is absolutely no need for
Locked_Queue<> to be a template, and neither should all methods be inlined.

Other issues: DispatchNotifier::create_pipe() calls g_win32_error_message()
whereas warn_failed_pipe_io() uses g_strerror(), so I guess the latter is
incorrect.  Also, the win32 code should pass the name of the function which
returned the error to warn_failed_pipe_io().
Comment 16 Daniel Elstner 2004-05-20 20:53:58 UTC
Created attachment 27890 [details] [review]
fixed-up patch

It would be nice if someone could try the new patch on Win32.  I hope it
compiles cleanly; right now I have now way to test glibmm on Win32.
Comment 17 Cedric Gustin 2004-05-24 13:36:46 UTC
I tried the new dispatcher against the current glibmm CVS on win32 (mingw-gcc 
2.3.2). dispatcher.cc and the two dispatcher examples compile fine. The 
dispatcher2.exe example runs as expected. The other example (dispatcher.exe) 
crashes with a segmentation fault when the last (5th) thread reaches 100% 
(finished).

I'm investigating...
Comment 18 Murray Cumming 2004-08-09 13:23:44 UTC
Status?
Comment 19 Cedric Gustin 2004-08-10 08:19:18 UTC
I found the bug in the dispatcher.cc example.  It is related to the use of
auto_ptr. In the on_progress_finish method, a ThreadProgress pointer was removed
from progress_list_ AND the corresponding object was deleted, which caused some
kind of race condition on win32.

To solve this problem, I removed the auto_ptr's. RefPtr's to the ThreadProgress
objects are now stored in a separate list (progress_ref_list_), which means that
the ThreadProgress objects are deleted when the Application destructor is
called. I think this is also a nice example of a RefPtr used with a non
Glib::Object (see the reference and unreference methods in ThreadProgress).

dispatcher now runs fine on win32, without memory leak.

If somebody could have a look at the code, test it on linux and comment...
Comment 20 Cedric Gustin 2004-08-10 08:20:47 UTC
Created attachment 30390 [details] [review]
Fixes crash of dispatcher example on win32
Comment 21 Cedric Gustin 2004-08-17 15:02:36 UTC
Somebody had time to try my latest patch ? Should I commit it to CVS ?
Comment 22 Murray Cumming 2004-08-18 07:06:25 UTC
Please ask for testers on the list, and then commit after a couple of days if
there are no problems reported (even if nobody tests it). I can't do it right
now. Thankyou.
Comment 23 Murray Cumming 2004-09-13 12:22:35 UTC
It seems like time to commit this.
Comment 24 Cedric Gustin 2004-09-13 12:45:21 UTC
Commited and (hopefully) resolved.
Comment 25 Daniel Elstner 2007-01-20 11:07:53 UTC
I accidentally found the real cause of the race condition Cedric experienced.  It was actually a bug in my patch, not in the example.

Also, I just reworked the win32 implementation somewhat (sticking closely to msdn) in order to make it match the Dispatcher behavior on Unix more closely.  The code compiles fine with dummy definitions of the win32 API functions, but I haven't tested yet whether it works at runtime.

Cedric, if (and only if) you have the time, I'd appreciate if you could try whether current glibmm/trunk works for you on win32.  I could also send you a patch instead if that would make matters easier for you.
Comment 26 Cedric Gustin 2007-01-24 08:06:23 UTC
 
I tested your changes to dispatcher on the glibmm-2.12 svn branch. The library builds fine with mingw32. examples/thread/dispatcher.cc also returns the expected result. I guess it would be interesting to commit those changes to glibmm-2.12 as well. 
Comment 27 Daniel Elstner 2007-01-24 08:20:03 UTC
Many thanks, Cedric.  I'm glad that it works.  Could you also please try whether it works correctly with the call to Glib::usleep() in examples/thread/dispatcher.cc commented out?  If it does, I'll commit the changes to glibmm-2.12, too :-)
Comment 28 Daniel Elstner 2007-01-24 10:28:39 UTC
Oh, and while you're at it, could you please also try with the Glib::usleep() replaced by Glib::Thread::yield()?  Many thanks, again :-)
Comment 29 Cedric Gustin 2007-01-24 13:08:12 UTC
Attached are the outputs of the dispatcher example with Glib::usleep(), Glib::Thread::yield or none of the two.
Comment 30 Cedric Gustin 2007-01-24 13:09:30 UTC
Created attachment 81065 [details]
Output of dispatcher example with neither usleep nor yield
Comment 31 Cedric Gustin 2007-01-24 13:09:56 UTC
Created attachment 81066 [details]
Output of dispatcher example with usleep
Comment 32 Cedric Gustin 2007-01-24 13:10:22 UTC
Created attachment 81067 [details]
Output of dispatcher example with yield