473,320 Members | 1,600 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Multiple Threads, Race Conditions, and Concurrent Processing

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

Dec 4 '06 #1
4 1283


On 4 déc, 22:59, gnas...@gmail.com wrote:
Hello,

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.
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

Dec 5 '06 #2
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?



ad******@club-internet.fr wrote:
On 4 déc, 22:59, gnas...@gmail.com wrote:
Hello,

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.

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
Dec 5 '06 #3
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

Dec 5 '06 #4
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.

Dec 5 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: MikeE | last post by:
Hi all, What's the best way to queue up and wait for number of threads to complete. This problem was trivial in VC++ 6 but I'm finding it rather hard to solve in VB.NET. My calculations run...
32
by: Christopher Benson-Manica | last post by:
Is the following code legal, moral, and advisable? #include <iostream> class A { private: int a; public: A() : a(42) {}
2
by: J.Marsch | last post by:
Does anyone know of a good modeling methodology for dealing with threading issues? I normally like to keep threading as simple as possible, but I've come across a project where there may be...
9
by: Abhishek Srivastava | last post by:
Hello All, In IIS 6.0 We have a concept of worker processes and application pools. As I understand it, we can have multiple worker process per appliction pool. Each worker process is dedicated...
6
by: James Radke | last post by:
Hello, I have a multithreaded windows NT service application (vb.net 2003) that I am working on (my first one), which reads a message queue and creates multiple threads to perform the processing...
5
by: Jeremy | last post by:
I have a core VB service that monitors a database, and based on data in the records will execute code to send email notifications. Problem: I don't want my main program code to halt and wait for...
35
by: Carl J. Van Arsdall | last post by:
Alright, based a on discussion on this mailing list, I've started to wonder, why use threads vs processes. So, If I have a system that has a large area of shared memory, which would be better? ...
167
by: darren | last post by:
Hi I have to write a multi-threaded program. I decided to take an OO approach to it. I had the idea to wrap up all of the thread functions in a mix-in class called Threadable. Then when an...
3
by: scriptlearner | last post by:
I am trying to put up a queue (through a logging thread) so that all worker threads can ask it to log messages. However, the problem I am facing is that, well, the logging thread itself is running...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.