Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Re: Win32::Gui + Threading?

by Flame (Deacon)
on Nov 12, 2001 at 07:34 UTC ( [id://124729]=note: print w/replies, xml ) Need Help??


in reply to Re: Win32::Gui + Threading?
in thread Win32::Gui + Threading?

Well, this looks like it's suppost to support threads... and the thread module came with the thing...

I'll look into the other version of perl you pointed to.
C:\windows>perl -V Summary of my perl5 (revision 5 version 6 subversion 0) configuration: Platform: osname=MSWin32, osvers=4.0, archname=MSWin32-x86-multi-thread uname='' config_args='undef' hint=recommended, useposix=true, d_sigaction=undef usethreads=undef use5005threads=undef useithreads=define usemultip +licity=def ine useperlio=undef d_sfio=undef uselargefiles=undef use64bitint=undef use64bitall=undef uselongdouble=undef usesocks=u +ndef Compiler: cc='cl', optimize='-O1 -MD -DNDEBUG', gccversion= cppflags='-DWIN32' ccflags ='-O1 -MD -DNDEBUG -DWIN32 -D_CONSOLE -DNO_STRICT -DHAVE_D +ES_FCRYPT -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DPERL_MSVCRT_READFIX' stdchar='char', d_stdstdio=define, usevfork=false intsize=4, longsize=4, ptrsize=4, doublesize=8 d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=10 ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', + lseeksize =4 alignbytes=8, usemymalloc=n, prototype=define Linker and Libraries: ld='link', ldflags ='-nologo -nodefaultlib -release -libpath:"E:\ +Perl\lib\C ORE" -machine:x86' libpth="E:\Perl\lib\CORE" libs= oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib + comdlg32 .lib advapi32.lib shell32.lib ole32.lib oleaut32.lib netapi32.lib uui +d.lib wsoc k32.lib mpr.lib winmm.lib version.lib odbc32.lib odbccp32.lib msvcrt. +lib libc=msvcrt.lib, so=dll, useshrplib=yes, libperl=perl56.lib Dynamic Linking: dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' ' cccdlflags=' ', lddlflags='-dll -nologo -nodefaultlib -release -l +ibpath:"E: \Perl\lib\CORE" -machine:x86' Characteristics of this binary (from libperl): Compile-time options: MULTIPLICITY USE_ITHREADS PERL_IMPLICIT_CONTEX +T PERL_IMP LICIT_SYS Locally applied patches: ActivePerl Build 623 Built under MSWin32 Compiled at Dec 15 2000 16:27:07 @INC: E:/Perl/lib E:/Perl/site/lib .



-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GIT d- s:++ a--- C++++ UL P+++>++++ L+ E- W++>+++ N !o K- W+ O---- M-- V--
PS PE Y- PGP t++(+++) 5(+++)++++ X R+@ tv+ b+++ DI+ D- G e->+++ h! r-- y-
------END GEEK CODE BLOCK------
Translate

"Weird things happen, get used to it."

Flame ~ Lead Programmer: GMS

Replies are listed 'Best First'.
Re: Re: Re: Win32::Gui + Threading?
by wog (Curate) on Nov 12, 2001 at 08:00 UTC
    It's compiled to support "ithreads" (interperator threads), which are currently under development. The "Thread" module is for 5.005-style threads, which are not ithreads. 5.005-style threads are being abondoned, apparently because they create race conditions that cannot be resolved efficiently. I would advise against their use. If you are interested, there is an experimental "threads" module for ithreads access from perl code.

    The primary reason that it has threading support is to support forking emulation, because Windows does not have a OS-level fork call. (See perlfork.) You should be able to access threads this way, but beware that Win32::GUI might have some problems if you spawn threads while it's objects are in scope because it's (XS-based) destructors could be called prematurely, or twice. update: (These problems may occur if you merely have such objects in exsitence at time of forking, even.)

      Well, since you don't recomend threads, can you suggest a method to allow the program to send/rescieve the data necessary without locking up? Is it possible to do it with fork? If you have any potential solution, please explain it in detail... I'd like to learn, instead of just have the answer handed to me.

      Thanks


      -----BEGIN GEEK CODE BLOCK-----
      Version: 3.12
      GIT d- s:++ a--- C++++ UL P+++>++++ L+ E- W++>+++ N !o K- w+ O---- M-- V--
      PS PE Y- PGP t++(+++) 5(+++)++++ X R+@ tv+ b+++ DI+ D- G e->+++ h! r-- y-
      ------END GEEK CODE BLOCK------
      Translate

      "Weird things happen, get used to it."

      Flame ~ Lead Programmer: GMS

        I thought this task would be relatively easy. Basically, you'd fork off a "server" at the beginning of your script which would have a channel to your script, probably created with pipe. You'd send URLs to get over a pipe, and the other end would read them, fetch the URL, and return the URL over another pipe. (This scheme would basically be what is done under "Bidirectional Communication with Yourself" in perlipc.)

        Unfortunately, Win32::GUI makes watching for the response difficult. Under Tk, one can watch for "fileevents" and thus get notified when data is available on a filehandle (from Tk's main loop.) Win32::GUI does not have a generic filehandle watching mechanism. One could probably emulate it using Win32::GUI::Timer and non-blocking I/O:

        Basically, you'd periodically poll the pipe going into your script to see if it has data for you. So regularly, you'd try to sysread from your pipe which has been set non-blocking (so your GUI won't freeze). (update: You'd probably schedule these read attempts with Win32::GUI::Timer, of course.) I reccommend sysread, because you're probably going to need to do your own I/O buffering this case. You probably want a relatively short time interval, something to balance use of CPU with apparent speed. To enable non-blocking I/O, you'd use IO::Handle's blocking method with an argument of 0. To check for data from the socket, you'd read it (with sysread) and see if you got an error (undef return). If you got an error and $! was EAGAIN (see the Errno module), then there is no data on the pipe. If $! wasn't EAGAIN, but there was an error, then you'd probably want to die, because something weird would've happened. If you don't get an error, you can add that to your cache of the results (note that you probably won't get all such data at once). (You probably want to have some way of marking when the end of data is, possibly just prefixing data you send with the length of the data.)

        Personally, I'd prefer a solution where Win32::GUI was modified to support watching filehandles.

        update: I forewarn that this advice is untested. (Also updated phrasing slightly.)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://124729]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-04-24 13:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found