|
-
June 5th, 2010, 10:28 PM
#1
Update the shared variable in two parallel threads
Anyone help me??
i have a CArray ar and when i edited it thread 1, the shared variable doesn't change in thread 2, both thread are running at the same time.. i used Mutex, but nothing happened... please help me!
this is the body of my thread
....
while(true)
{
int can_download;
int i;
mt.Lock();
int n= ar.GetCount();
for(i=0; i<n;i++)
if(strcmp(ar[i].filename, srfile)==0)
break;
if(ar[i].port_request == prt)
{
can_download = 1;
m_down.Send(&can_download, sizeof(int), 0);
m_down.Send(srfile, 32768, 0);
int don;
m_down.Receive(&don, sizeof(int), 0);
if(don == 1)
ar.RemoveAt(i);
mt.Unlock();
break;
}
else
{
n = ar.GetCount();
mt.Unlock();
}
}
....
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
|