in reply to Class::Std::Fast cache and threads

Does anyone have any suggestions?

You have 3 options

Replies are listed 'Best First'.
Re^2: Class::Std::Fast cache and threads
by Boldra (Curate) on Oct 12, 2010 at 10:34 UTC
    Thanks for your reply

    I don't actually want anything from Class::Std::Fast in my child threads. The children are only using thread-safe classes. I'm trying to use Class::Std::Fast in the main thread, and then later do something completely unrelated in child threads.

    I understand that I could create a thread especially for Class::Std::Fast, using require instead of use,

    my $s = STR->new; $s->one; $s->two; $s->three;
    becomes
    threads->create( sub { require STR; STR->import; my $s = STR->new; $s->one; $s->two; $s->three; } )->join;
    This would get STR out of my main thread and into it's own private child thread, but this hardly seems like an elegant or maintainable solution. I'm going to want to import STR at least twice in my code, and create a new thread just for this each time.

    As for rewriting CPAN modules to meet my requirements, yes, using moose would be ideal, but I am lazy, and I'll comment out the croak in Class::Std::Fast first. I see no good reason why it should be there.

    Is there really no way to :

    1. trick caller()
    2. load a module in only the main thread
    ?
      load a module in only the main thread

      Use require in your main thread after you've started all your other threads.

        Thanks for the answer, but I dislike this due to the program flow it will force me into. It will look something like this:
        1. load most libraries
        2. create threads and put them to sleep
        3. load the soap libraries
        4. do some soap calls
        5. do some other things
        6. wake and use the threads, (passing arguments via a share I created earlier?)
        7. do some more soap calls
        Which I don't trust to be very maintainable.