Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / December 2006

Tip: Looking for answers? Try searching our database.

Multiple Threads, Race Conditions, and Concurrent Processing

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
gnassar@gmail.com - 04 Dec 2006 21:59 GMT
Hello,

I've written to this group a couple times and would like to initially
start by thanking those who reply to the posts. I seem to be having
some issues that are out of my understanding at the moment and
hopefully someone knowledgeable will be able to guide me the right way.

I have created a program that utilizes three threads minimum. The
initial gui thread, and two worker threads. I haven't set the worker
threads as background threads yet. The problem I am facing is that each
thread when opened initialized itself and begins sending a file to a
server on my network.

Essentially I'd like to transfer two files at the same time to a single
place. The only problem I'm facing is that after one starts, the other
file essentially stops sending. The thread doesn't continue processing.
Actually it does nothing.

I was wondering what information you'd need to help me out. I'm a bit
confused as to why this is happening.

TIA
G
adebaene@club-internet.fr - 05 Dec 2006 14:29 GMT
On 4 déc, 22:59, gnas...@gmail.com wrote:
> Hello,
>
[quoted text clipped - 8 lines]
> file essentially stops sending. The thread doesn't continue processing.
> Actually it does nothing.

What do you mean by "a single place". Do you mean you want to copy 2
fines in the same network directory?

How are you "sending" the files? Give us more details, or show us a
minimum code sample.

Arnaud
MVP - VC
gnassar@gmail.com - 05 Dec 2006 21:24 GMT
Hi Arnaud,

Thanks for the reply. Essentially the code for transferring the files
works. There's no issue in that.

I have two classes. The main one: Form1 and the secondary thread:
dthread. Essentially the transferring processes all occurs within
dthread. So, once you instantiate dthread in another thread it starts
sending files.

dthread
public:
    public: void ThreadCallBack(Object^ threadContext);

The thread starts when it calls: ThreadCallBack in dthread. Via:

MRE[i] = gcnew ManualResetEvent(true);
dthread^ t = gcnew dthread(this->clb_List->Items[a]->ToString(),
MRE[i]);
WTHREAD[i] = t;
System::UInt32^ m_i = gcnew UInt32(i);

//ThreadPool::QueueUserWorkItem(gcnew
System::Threading::WaitCallback(t, &dthread::ThreadCallBack),this);

Thread^ newThread =
gcnew Thread(gcnew ParameterizedThreadStart(t,
&dthread::ThreadCallBack));
ThreadList[i] = newThread;

newThread->Start(this);
break;

You'll notice that this seems to be done to use a ThreadPool. I changed
it to normal threads thinking that would solve the issue. It didn't
seem to be that way. Inside ThreadCallBack we have:

if (ParentThread->InvokeRequired){
    IAsyncResult^ A = ParentThread->BeginInvoke(gcnew
GetTextDelegate(this, &dthread::GetTextD));
    M = (String^) ParentThread->EndInvoke(A);
}

ParentThread->BeginInvoke(gcnew SetStatusTextDelegate(this,
&dthread::WriteStatusInformation),
(Object^)(gcnew String("Thread: " + _n.ToString() + " Is sending: " +
M->ToString())));

if (!Execute(M)){
   ParentThread->BeginInvoke(gcnew SetStatusTextDelegate(this,
&dthread::WriteStatusInformation),
(Object^)(gcnew String("Thread Forced Exit On: " + M + ". Error
Detected.")));
_doneEvent->Set();
return;
}

Execute is where I get the next file to be sent, then continues to loop
while getting files from  the list box.

I have two threads. They're created above and placed into an array just
for a way to access them. Both threads hit the point of executing
"GetTextD". The problem is only one continues and attempts to send
files. The first stays there. At least I think it's there.

I was wondering shouldn't they be racing each other? Both attempting to
send files?

> On 4 déc, 22:59, gnas...@gmail.com wrote:
> > Hello,
[quoted text clipped - 18 lines]
> Arnaud
> MVP - VC
gnassar@gmail.com - 05 Dec 2006 22:08 GMT
Update:

I've discovered something interesting.
If the program is set to use 3 threads, two threads can send files, but
one of them is blocked. I can't seem to pinpoint where though.

TIA
gnassar@gmail.com - 05 Dec 2006 22:57 GMT
I've pinpointed the problem:
When I do:
Stream^ loPostData = Request->GetRequestStream();

Within two threads at near close times I assume one fails. Thus killing
the thread. Not sure why but I placed a delay
Thread::Sleep(randobj->next()) it seemed to have fixed the issue
temporarily.

I'm sure thats not the optimal solution.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.