Workerthread and member variables? - Programmer

This is a discussion on Workerthread and member variables? - Programmer ; All, Simple question: I have a CArray member variable m_aUsers which is a member of a property sheet CUsersPage. I am aware that I can call CreateThread with a generic function which will populate a standard CArray but can I ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: Workerthread and member variables?

  1. Workerthread and member variables?

    All,

    Simple question: I have a CArray member variable m_aUsers which is a member
    of a property sheet CUsersPage.

    I am aware that I can call CreateThread with a generic function which will
    populate a standard CArray but can I populate the member CArray in a WINAPI
    workerthread? If so what is the easiest way to go about it?

    PT



  2. Re: Workerthread and member variables?

    Paul Tomlinson wrote:
    > All,
    >
    > Simple question: I have a CArray member variable m_aUsers which is a member
    > of a property sheet CUsersPage.
    >
    > I am aware that I can call CreateThread with a generic function which will
    > populate a standard CArray but can I populate the member CArray in a WINAPI
    > workerthread? If so what is the easiest way to go about it?
    >
    > PT
    >
    >


    Yes, you can. The member CArray is no different than a "standard"
    CArray (whatever that means). You can simply pass a pointer to your
    member CArray to the thread function. The thread function will have to
    cast it back into a CArray pointer.

    Incidentally, you should use AfxBeginThread in an MFC program. It calls
    CreateThread for you. But even if you use CreateThread it can access a
    member OK.

    The usual multithreading precautions apply. You must synchronize access
    if there is any possiblity of multiple threads accessing the member
    concurrently, and you must make sure the thread has exited before you
    destroy the CArray.

    --
    Scott McPhillips [VC++ MVP]


+ Reply to Thread