CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 1999
    Location
    Germany
    Posts
    53

    CWinThread and Vars

    Hi,

    I have several Threads of following class running:

    class CThreadTest : public CWinThread
    {
    public:
    DECLARE_DYNCREATE( CThreadTest )

    virtual BOOL InitInstance();
    virtual int Run();

    char recv_Data[1024];
    }




    Everything works fine, but I want to know, if recv_Data is local on each thread? That means if I modify recv_Data on each Thread at the same time, do I change it in every Thread and is it in every Thread the same then?

    I hope u understand my problem.

    Thanx in advance.

    Karsten


  2. #2
    Guest

    Re: CWinThread and Vars

    Unless you are doing something REALLY peculiar, the answer is "YES": each thread and it's associated object will have a local copy of recv_Data[]. Changing the value of recv_Data[] in one thread will NOT affect the value in any other threads.

    Cheers!
    Humble Programmer
    ,,,^..^,,,


  3. #3
    Join Date
    Apr 1999
    Location
    Germany
    Posts
    53

    Re: CWinThread and Vars

    Hi,

    why is my code a bit strange? can u tell me please?


  4. #4
    Guest

    Re: CWinThread and Vars

    Your code is find...don't read anything into my previous posting. One word of advice, however: don't hardcode "magic numbers" in your code, because it makes it harder to maintain. May I suggest:

    const kBufferSize = 1024;

    class CTestThread : public CWinThread
    {
    ...
    BYTE m_recvData[kBufferSize];
    ...
    };



    Cheers!
    Humble Programmer
    ,,,^..^,,,


  5. #5
    Join Date
    May 1999
    Posts
    35

    Re: CWinThread and Vars

    Hi,

    before you can run your thread you have to create an instance of your class CThreadTest. That means that the members are local for each instance. Only static members are shared between the instances. But be careful with shared data and keep assured that concurrency access is blocked e.g. with a mutex object.

    Greetings, Jörg



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured