|
-
May 27th, 1999, 03:34 AM
#1
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
-
May 27th, 1999, 04:12 AM
#2
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
,,,^..^,,,
-
May 27th, 1999, 04:16 AM
#3
Re: CWinThread and Vars
Hi,
why is my code a bit strange? can u tell me please?
-
May 27th, 1999, 04:54 AM
#4
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
,,,^..^,,,
-
May 27th, 1999, 05:11 AM
#5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|