renodino has asked for the wisdom of the Perl Monks concerning the following question:

I've just finished the first release of Thread::Apartment, and seek the indulgence of, and feedback from, the monastery.

Note: Thread::Apartment has not yet been CPAN'd, as I hope to exersize it more thoroughly in an application I'm developing... and perhaps get some feedback from the Monks in the interim...

(For the unfamiliar, apartment threading is a method of isolating an object (or object hierarchy) within its own thread and exposing its interfaces via lightweight proxy objects.)

Background: My initial attempt at apartment threading occured while trying to make DBI more "threadable". The result was DBIx::Threaded, and the associated module Thread::Queue::Duplex. Once I managed to get that running, I realized

  1. I really needed a general apartment threading solution for a complex application I'm working on that has significant concurrency and scalability requirements
  2. I could probably leverage the experiences gleened from DBIx::Threaded to develop a more generalized apartment threading wrapper for Perl objects
  3. With such a wrapper, I could quite possibly expose other complex, legacy modules in a thread-safe way (most notably for my purposes, Perl/Tk)

While this initial release falls short of permitting (3) (due to unimplemented support for closure proxies), I think I've covered most of the important ground to make OO Perl more "threadable" (albeit, at some performance expense) ala Java's threading capabilities.

I've also begun pondering whether Thread::Apartment may also provide a nice foundation for fully distributed objects (tho without the use of threads::shared elements). Assuming that some sockets or IPC based subclasses of Thread::Queue::Duplex, Thread::Apartment::Server, and Thread::Apartment::Client were created, it should be feasible to build fully distributed object architectures entirely in Perl.

Have I overlooked something simple in Perl that already handles all of this ? Or worse, overlooked something which could cause this house of cards to tumble ?

Comments/suggestions/concerns welcome.

Replies are listed 'Best First'.
Re: Apartment Threading in Perl
by InfiniteSilence (Curate) on Sep 01, 2005 at 22:33 UTC
    Bummer, no Storable PPM on the ActiveState website for Win32 and CPAN only has links to v2.12:
    perl makefile.pl Warning: prerequisite Class::Inspector 1.08 not found. Warning: prerequisite Storable 2.15 not found. We have 2.13. Warning: prerequisite Thread::Queue::Duplex 0.14 not found.
    Does this module really need 2.15?

    Celebrate Intellectual Diversity

      Er, here's where I got it... Not certain T::A needs 2.15, I just grabbed the most recent version I found on CPAN...which is 2.15
Re: Apartment Threading in Perl
by BrowserUk (Patriarch) on Sep 02, 2005 at 04:38 UTC

    Having installed and tested the dependancies, make test of Thread::Apartment segfaults during test 9 (or 10?).

    What other information would be useful?

    P:\packages\Thread-Apartment-0.10>perl -v This is perl, v5.8.4 built for MSWin32-x86-multi-thread (with 3 registered patches, see perl -V for more detail) Copyright 1987-2004, Larry Wall Binary build 810 provided by ActiveState Corp. http://www.ActiveState. +com ActiveState is a division of Sophos. Built Jun 1 2004 11:52:21 P:\packages\Thread-Apartment-0.10>nmake clean Microsoft (R) Program Maintenance Utility Version 8.00.40607.16 Copyright (C) Microsoft Corporation. All rights reserved. C:\perl5.8.6\bin\perl.exe -MExtUtils::Command -e rm_rf ./blib +Makefile.aperl blib\arch\auto\Thread\Apartment/extralibs.all blib\arc +h\a C:\perl5.8.6\bin\perl.exe -MExtUtils::Command -e mv Makefile M +akefile.old > NUL C:\perl5.8.6\bin\perl.exe -MExtUtils::Command -e rm_f *.pdb P:\packages\Thread-Apartment-0.10>makefile main::CheckModule() called too early to check prototype at P:\packages +\Thread-Apartment-0.10\Makefile.PL line 41. Configuring Thread::Apartment ... Checking for Thread::Queue::Duplex, 0.14 or later ... ok Checking for Storable, 2.15 or later ... ok Checking for Class::ISA, 0.32 or later ... ok Checking for Class::Inspector, 1.08 or later ... ok Checking if your kit is complete... Looks good Writing Makefile for Thread::Apartment P:\packages\Thread-Apartment-0.10>nmake test Microsoft (R) Program Maintenance Utility Version 8.00.40607.16 Copyright (C) Microsoft Corporation. All rights reserved. cp lib/Thread/Apartment.pm blib\lib\Thread\Apartment.pm cp lib/Thread/Apartment/Client.pm blib\lib\Thread\Apartment\Client.pm cp lib/Thread/Apartment/Common.pm blib\lib\Thread\Apartment\Common.pm cp lib/Thread/Apartment/IOServer.pm blib\lib\Thread\Apartment\IOServer +.pm cp lib/Thread/Apartment/Server.pm blib\lib\Thread\Apartment\Server.pm cp lib/Thread/Apartment/Closure.pm blib\lib\Thread\Apartment\Closure.p +m C:\perl5.8.6\bin\perl.exe "-MExtUtils::Command::MM" "-e" "test +_harness(0, 'blib\lib', 'blib\arch')" t\01test.t t\01test....Note: some tests have significant delays... t\01test....dubious Test returned status 5 (wstat 1280, 0x500) DIED. FAILED tests 10-125 Failed 116/125 tests, 7.20% okay Failed Test Stat Wstat Total Fail Failed List of Failed ---------------------------------------------------------------------- +--------- t\01test.t 5 1280 125 232 185.60% 10-125 Failed 1/1 test scripts, 0.00% okay. 116/125 subtests failed, 7.20% ok +ay. NMAKE : fatal error U1077: 'C:\perl5.8.6\bin\perl.exe' : return code ' +0x2' Stop.

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.
      Hmm, I'm running a similar setup, tho your perl -V report and the directory path seem out of sync (one is 5.8.4, the other is 5.8.6 ? And the AS build is 810, which I think was the original 5.8.6, but they later released an update build 811)

      Could you just run the t/01test.t standalone ? (You'll have to go ahead and "nmake install" to run it). That might expose more info about whats going wrong.

      In the meantime, I'll give it a shot on OS X, and maybe Solaris. Alas, my Linux (Fedora Core 4) has exhibited bizarre behavior w/ recent perl versions. FWIW: here's my perl info:

      D:\Perl\Thread-Apartment-0.10\t>perl -v This is perl, v5.8.6 built for MSWin32-x86-multi-thread (with 3 registered patches, see perl -V for more detail) Copyright 1987-2004, Larry Wall Binary build 811 provided by ActiveState Corp. http://www.ActiveState. +com ActiveState is a division of Sophos. Built Dec 13 2004 09:52:01
      Thanks for testing.

      Update:

      Just tested on OS X 10.3.9 w/ AS 5.8.7, and it ran swimmingly. Perhaps its a AS 5.8.4 issue ? Tho the fact that you presumably were able to test Thread;:Queue::Duplex prior to install is curious...

      Update 2:

      Tested on Solaris 10 w/ perl 5.8.6, also runs swimmingly.

        Okay. I reverted to my 5.8.4 installation, and rebuilt from scratch and then ran the 01test.t with the same result. A segfault when running either test 9 or 10. I looked into 01test.t, but couldn't easily work out which test corresponded to which number as several are commented out, and it's not obvious from teh data logged exactly which test (9 or 10) is actually giving the segfault?

        P:\packages\Thread-Apartment-0.10>perl -V Summary of my perl5 (revision 5 version 8 subversion 4) 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=define useperlio=define d_sfio=undef uselargefiles=define usesocks=undef use64bitint=undef use64bitall=undef uselongdouble=undef usemymalloc=n, bincompat5005=undef Compiler: cc='cl', ccflags ='-nologo -Gf -W3 -MD -Zi -DNDEBUG -O1 -DWIN32 -D +_CONSOLE -DNO_STRICT -DHAVE_DES_FCRYPT -DNO_HASH_SEED -DPERL_IMPLICI +T_CON optimize='-MD -Zi -DNDEBUG -O1', cppflags='-DWIN32' ccversion='', gccversion='', gccosandvers='' intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234 d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=10 ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='__int64 +', lseeksize=8 alignbytes=8, prototype=define Linker and Libraries: ld='link', ldflags ='-nologo -nodefaultlib -debug -opt:ref,icf -l +ibpath:"c:\Perl\lib\CORE" -machine:x86' libpth=C:\PROGRA~1\MICROS~3\VC98\lib libs= oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib + comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib netap +i32.l perllibs= oldnames.lib kernel32.lib user32.lib gdi32.lib winspool +.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib n +etapi libc=msvcrt.lib, so=dll, useshrplib=yes, libperl=perl58.lib gnulibc_version='undef' Dynamic Linking: dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' ' cccdlflags=' ', lddlflags='-dll -nologo -nodefaultlib -debug -opt: +ref,icf -libpath:"c:\Perl\lib\CORE" -machine:x86' Characteristics of this binary (from libperl): Compile-time options: MULTIPLICITY USE_ITHREADS USE_LARGE_FILES PERL +_IMPLICIT_CONTEXT PERL_IMPLICIT_SYS Locally applied patches: ActivePerl Build 810 22751 Update to Test.pm 1.25 21540 Fix backward-compatibility issues in if.pm Built under MSWin32 Compiled at Jun 1 2004 11:52:21 @INC: c:/Perl/lib c:/Perl/site/lib . P:\packages\Thread-Apartment-0.10>nmake realclean Microsoft (R) Program Maintenance Utility Version 8.00.40607.16 Copyright (C) Microsoft Corporation. All rights reserved. C:\Perl\bin\perl.exe -MExtUtils::Command -e rm_rf ./blib Makef +ile.aperl blib\arch\auto\Thread\Apartment/extralibs.all blib\arch\aut +o\Thr C:\Perl\bin\perl.exe -MExtUtils::Command -e mv Makefile Makefi +le.old > NUL C:\Perl\bin\perl.exe -MExtUtils::Command -e rm_f *.pdb C:\Perl\bin\perl.exe -MExtUtils::Command -e rm_rf blib\lib\aut +o\Thread\Apartment blib\arch\auto\Thread\Apartment C:\Perl\bin\perl.exe -MExtUtils::Command -e rm_rf Thread-Apart +ment-0.10 C:\Perl\bin\perl.exe -MExtUtils::Command -e rm_f blib\lib\Thr +ead\Apartment\Common.pm blib\lib\Thread\Apartment\Server.pm Makefile. +old b C:\Perl\bin\perl.exe -MExtUtils::Command -e rm_f blib\lib\Thre +ad\Apartment\IOServer.pm Makefile P:\packages\Thread-Apartment-0.10>makefile main::CheckModule() called too early to check prototype at P:\packages +\Thread-Apartment-0.10\Makefile.PL line 41. Configuring Thread::Apartment ... Checking for Thread::Queue::Duplex, 0.14 or later ... ok Checking for Storable, 2.15 or later ... ok Checking for Class::ISA, 0.32 or later ... ok Checking for Class::Inspector, 1.08 or later ... ok Checking if your kit is complete... Looks good Writing Makefile for Thread::Apartment P:\packages\Thread-Apartment-0.10>nmake test Microsoft (R) Program Maintenance Utility Version 8.00.40607.16 Copyright (C) Microsoft Corporation. All rights reserved. cp lib/Thread/Apartment.pm blib\lib\Thread\Apartment.pm cp lib/Thread/Apartment/Client.pm blib\lib\Thread\Apartment\Client.pm cp lib/Thread/Apartment/Common.pm blib\lib\Thread\Apartment\Common.pm cp lib/Thread/Apartment/IOServer.pm blib\lib\Thread\Apartment\IOServer +.pm cp lib/Thread/Apartment/Server.pm blib\lib\Thread\Apartment\Server.pm cp lib/Thread/Apartment/Closure.pm blib\lib\Thread\Apartment\Closure.p +m C:\Perl\bin\perl.exe "-MExtUtils::Command::MM" "-e" "test_harn +ess(0, 'blib\lib', 'blib\arch')" t\01test.t t\01test....Note: some tests have significant delays... t\01test....dubious Test returned status 5 (wstat 1280, 0x500) DIED. FAILED tests 10-125 Failed 116/125 tests, 7.20% okay Failed Test Stat Wstat Total Fail Failed List of Failed ---------------------------------------------------------------------- +--------- t\01test.t 5 1280 125 232 185.60% 10-125 Failed 1/1 test scripts, 0.00% okay. 116/125 subtests failed, 7.20% ok +ay. NMAKE : fatal error U1077: 'C:\Perl\bin\perl.exe' : return code '0x2' Stop. P:\packages\Thread-Apartment-0.10>C:\Perl\bin\perl.exe "-MExtUtils::Co +mmand::MM" "-e" "test_harness(0, 'blib\lib', 'blib\arch')" t\01test.t t\01test....Note: some tests have significant delays... t\01test....dubious Test returned status 5 (wstat 1280, 0x500) DIED. FAILED tests 10-125 Failed 116/125 tests, 7.20% okay Failed Test Stat Wstat Total Fail Failed List of Failed ---------------------------------------------------------------------- +--------- t\01test.t 5 1280 125 232 185.60% 10-125 Failed 1/1 test scripts, 0.00% okay. 116/125 subtests failed, 7.20% ok +ay.

        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
        "Science is about questioning the status quo. Questioning authority".
        The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.
      My assumption is its test number 10, which is the first test which actually attempts to make a method call: (from 01test.t)
      my $result = $obj->thirdBase(); report_result($testno, defined($result) && ($result eq 'thirdbase'), ' +simple method', '', $@);
      Again, if possible, try running the 01test.t script standalone, outside of nmake test. That should provide more info about what is actually failing (tho it will require an "nmake install").

        Okay. I will do that. Unfortunately I have some doubts about the integrity of my 5.8.4 install, so I am going to wipe it and re-install from scratch and re-build/install all of my modules. I will have to re-download several of them so it may be a day or so before I respond further.


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
        "Science is about questioning the status quo. Questioning authority".
        The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.
Re: Apartment Threading in Perl
by Zukoff (Initiate) on Nov 20, 2006 at 17:04 UTC
    We need samples!!! Samples!!!