Inter-thread communication to pass a job to another thread

J

James Lavery

Hi everyone,
We're developing an application to capture data from several serial
ports, store in a database, and (optionally) forward on using FTP.

Each serial port is being processed in a thread, so that capture of
data can continue if the UI is blocked with a modal dialg, for
example.

I would like each thread to be able to pass any FTP work to a
dedicated thread, so that its data capture is not interrupted if the
FTP takes a long time.

So what I'm looking at is:

main thread
--- capture thread A
--- capture thread B
--- ftp thread

The big question is: how do I pass the ftp data from threads A/B to
the FTP thread?

In a similar vein, am I going to have problems if thread A and thread
B are both writing to my MSDE database?

The other question, of course, is whether there's a better way to do
it!

Any pointers greatly appreciated!

Thanks,

James
 
C

Cor Ligthert

Hi James,

This seams a bit as Charles Law is busy with, however I get the idea you
have fixed the part of the serial port to the database as I understand your
question well. Maybe you can have a look at his problem in this newsgroup
and give him some advices.

In my opinion is the FTP is a File Transfer Protocol, so you can only send
file by file (that can be done in more threads) however in my idea that can
only be done when the file is complete.

In a message I gave Charles the idea to use a queue. The same idea I get
when I hear your problem. To Charles I said that a simple arraylist is very
suitable for his problem in my opinion. However for you problem I think that
can be even more. Putting in that queue the files which have to be
transfered can be a very simple sollution in combination with
multithreading.

When I do miss something, tell me what I miss?

Cor
 
C

Charles Law

Hi James

How about creating two classes: one which contains a (thread) method that
performs the data capture, and one that contains a method that performs ftp
work.

Create objects of these two classes and start the threads going from you UI
thread. Then you can carry on doing UI stuff.

When the data capture thread gets ftp work to be done, have it raise an
event that is handled in your UI thread. All the handler does is place the
work in a queue managed by the ftp thread, and pulses the queue object to
inform the ftp thread that something is ready. The UI thread then returns to
what it was doing.

If you don't want the UI thread to be bothered by any of this, you could
have a thread that just waits for events from data capture threads and
passes them to the ftp thread.

HTH

Charles
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top