Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Threads and object access

by Nitrox (Chaplain)
on Dec 11, 2002 at 22:34 UTC ( #219200=note: print w/replies, xml ) Need Help??


in reply to Threads and object access

I was afraid of that BrowserUk.

So for the time being can anyone suggest a viable alternative?

The child thread simply sits in a while loop polling the serial port. When data is received the child then needs to be able to access $HS as is $HS->GotEvent(). Seeing as the child can't make the call directly what's the best way to instruct the parent to make the call. Or is it possible for a child thread to explicitly call a subroutine in the parent thread instead of it's own?

-Nitrox

Replies are listed 'Best First'.
Re: Re: Threads and object access
by BrowserUk (Patriarch) on Dec 12, 2002 at 00:07 UTC

    One mechanism would be to use signals or semaphores and a shared data buffer.

    The child thread get its data, puts it into the shared buffer and then signals (semaphores) when it has put something in the buffer to process.

    (Win32::Semaphore is one possibility, but there is Threads::Semaphore in 5.8, but I am being a luggard and haven't got around to upgrading yet).

    You don't say what the parent thread is doing, but it would need to check (with timeout if necessary) for the semaphore and then take the appropriate action on behalf of the child.


    Okay you lot, get your wings on the left, halos on the right. It's one size fits all, and "No!", you can't have a different color.
    Pick up your cloud down the end and "Yes" if you get allocated a grey one they are a bit damp under foot, but someone has to get them.
    Get used to the wings fast cos its an 8 hour day...unless the Govenor calls for a cyclone or hurricane, in which case 16 hour shifts are mandatory.
    Just be grateful that you arrived just as the tornado season finished. Them buggers are real work.

      The parent thread is pretty usless and is held in a "by-call state" by the PerlCtrl internals, which is why I was forced to spawn a child to do my polling.

      -Nitrox

        I suppose if you bypassed the problem by creating your Win::OLE object in the child thread, you'd end up with the same problem later when you need to do something with it in the parent?


        Okay you lot, get your wings on the left, halos on the right. It's one size fits all, and "No!", you can't have a different color.
        Pick up your cloud down the end and "Yes" if you get allocated a grey one they are a bit damp under foot, but someone has to get them.
        Get used to the wings fast cos its an 8 hour day...unless the Govenor calls for a cyclone or hurricane, in which case 16 hour shifts are mandatory.
        Just be grateful that you arrived just as the tornado season finished. Them buggers are real work.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2023-06-01 16:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?