Subject: HOWTO: write C++/multithreaded extensions for Win32 + example code - DN [1]
davygrvy@bigfoot.com (David Gravereaux) - 18 Jul 1999 - comp.lang.tcl
I thought I'd make my source code public and help the Tcl community a bit. I had to write this for a recent project and thought I would share it. The following link is to some free C++ source code for MSVC++: http://www.maui.net/~davygrvy/files/ghe_dirwatch.zip First, this is what the extension does. It enables directory watches and fires a script in the origin interpreter when a file in that directory has been written to. In wish81 or wish82: % load ghe_dirwatch.dll % GHE::startwatch c:/temp {puts "got ya!"} watch0 got ya! <- dropped a file into the c:\temp folder got ya! <- dropped another (immediate; no delay like polling) % GHE::endwatch watch0 It uses these Win32 functions to enable the watch: FindFirstChangeNotification() FindNextChangeNotification() and FindCloseChangeNotification() The interface to Tcl is a single class instantiated in the Init function. Each interp calling into it has a separate instance of this class. A striped-down version of it can be found here: http://www.maui.net/~davygrvy/files/test.cpp When the GHE::startwatch command is called from Tcl, a new thread is created which is then "waited on" with WaitForMultipleEvents(). A copy of the script command and a reference to the per interp thread-safe workqueue is also given to the new thread. When the event fires, the script Tcl_Obj is Put() to the workqueue and calls Tcl_AsyncMark with the token handed to it when the main per interp (CTclTop) class was instantiated. When Tcl enters the Async proc, the script to run is pulled off the thread-safe workqueue and queued into Tcl with Tcl_QueueEvent(). Eventually, this comes around in the notifier and is evaluated. More info and detail about this 3 part Tcl thread-safe technique can be found here: http://www.maui.net/~davygrvy/tomahawk/irc_engine_oline.html This code follows my own convention and is not the same as what the tcl8.1 man pages says about threads. If you found this helpful, please email me some praise or better yet.... HIRE ME FOR YOUR MULTITHREADED TCL PROJECTS!! with Love and respect, * David Gravereaux * Tomahawk Software Group
Last modified
1999-09-27
1999-09-27
(195.108.246.50)
Note: you are looking at
the snapshot of an old wiki
- much of this information
is likely to be very outdated
