473,383 Members | 1,803 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,383 software developers and data experts.

Threading question....

I am having trouble figuring out the best what to accomplish this fairly
simple goal. I have a program that controls a 1-wire network and I can only
make requests to it one at a time, but I will need to make new requests
(from multiple threads) before the first one is done. My idea is to use a
Queue to add requests to and then have another process (thread) that will
simply wait for the Queue to not be empty and then process requests one at a
time until it is empty and then again wait for the Queue to not be empty.

I'm looking for a basic framework of what would be best way to do this using
what Classes and how to signal between threads (if needed?). I would use
Queue, Thread? and ??

Any help is appreciated.

Norm

Jan 21 '06 #1
4 1070
Do you care about the order the requests are handled? If not, put your
network handler in a module (class or regular) and then use the following
code around your "critical section"

static SyncObj as new Object
Synclock SyncObj
' Process Critical Section
End SyncLock

Note that SyncObj is static as it must stick around for the life of the
application. What this does is stops all threads and forces them to wait
until the previous thread is complete with the network IO.

Mike Ober.

"Justin" <justin23856 @ hotmail> wrote in message
news:e9**************@TK2MSFTNGP14.phx.gbl...
I am having trouble figuring out the best what to accomplish this fairly
simple goal. I have a program that controls a 1-wire network and I can only make requests to it one at a time, but I will need to make new requests
(from multiple threads) before the first one is done. My idea is to use a
Queue to add requests to and then have another process (thread) that will
simply wait for the Queue to not be empty and then process requests one at a time until it is empty and then again wait for the Queue to not be empty.

I'm looking for a basic framework of what would be best way to do this using what Classes and how to signal between threads (if needed?). I would use
Queue, Thread? and ??

Any help is appreciated.

Norm


Jan 22 '06 #2
Mike,

Thanks for the input. However, that is exactly what I am doing now, and I
do (now) care about the sequence of requests. That is why I was thinking of
using the Queue class to hold requests. The main part I'm having trouble
with is in another thread processing those requests in the Queue and letting
the thread that added the request to the queue know that its request has
been fulfilled. And, also how to make the Queue processing thread 'sleep'
until the Queue.count is > 0.

As an aside... I was wondering if you know the difference between using
SyncLock/End SyncLock and Monitor.Enter/Monitor.Exit?

Thanks again for any input!

Norm
"Michael D. Ober" <obermd.@.alum.mit.edu.nospam> wrote in message
news:St***************@newsread3.news.pas.earthlin k.net...
Do you care about the order the requests are handled? If not, put your
network handler in a module (class or regular) and then use the following
code around your "critical section"

static SyncObj as new Object
Synclock SyncObj
' Process Critical Section
End SyncLock

Note that SyncObj is static as it must stick around for the life of the
application. What this does is stops all threads and forces them to wait
until the previous thread is complete with the network IO.

Mike Ober.

"Justin" <justin23856 @ hotmail> wrote in message
news:e9**************@TK2MSFTNGP14.phx.gbl...
I am having trouble figuring out the best what to accomplish this fairly
simple goal. I have a program that controls a 1-wire network and I can

only
make requests to it one at a time, but I will need to make new requests
(from multiple threads) before the first one is done. My idea is to use
a
Queue to add requests to and then have another process (thread) that will
simply wait for the Queue to not be empty and then process requests one
at

a
time until it is empty and then again wait for the Queue to not be empty.

I'm looking for a basic framework of what would be best way to do this

using
what Classes and how to signal between threads (if needed?). I would use
Queue, Thread? and ??

Any help is appreciated.

Norm


Jan 22 '06 #3
Justin,

In this case, create a new class that inherits from the Queue class.
Override the Enqueue (Add) and Dequeue (Remove) methods and put a synclock
around the actual add and remove methods of the queue class. This way your
new class is thread safe.

I haven't used the Monitor.Enter/Monitor.Exit interface - SyncLock and
AutoResetEvents have been sufficient for my needs.

Mike.

"Justin" <justin23856 @ hotmail> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Mike,

Thanks for the input. However, that is exactly what I am doing now, and I do (now) care about the sequence of requests. That is why I was thinking of using the Queue class to hold requests. The main part I'm having trouble
with is in another thread processing those requests in the Queue and letting the thread that added the request to the queue know that its request has
been fulfilled. And, also how to make the Queue processing thread 'sleep'
until the Queue.count is > 0.

As an aside... I was wondering if you know the difference between using
SyncLock/End SyncLock and Monitor.Enter/Monitor.Exit?

Thanks again for any input!

Norm
"Michael D. Ober" <obermd.@.alum.mit.edu.nospam> wrote in message
news:St***************@newsread3.news.pas.earthlin k.net...
Do you care about the order the requests are handled? If not, put your
network handler in a module (class or regular) and then use the following code around your "critical section"

static SyncObj as new Object
Synclock SyncObj
' Process Critical Section
End SyncLock

Note that SyncObj is static as it must stick around for the life of the
application. What this does is stops all threads and forces them to wait until the previous thread is complete with the network IO.

Mike Ober.

"Justin" <justin23856 @ hotmail> wrote in message
news:e9**************@TK2MSFTNGP14.phx.gbl...
I am having trouble figuring out the best what to accomplish this fairly simple goal. I have a program that controls a 1-wire network and I can

only
make requests to it one at a time, but I will need to make new requests
(from multiple threads) before the first one is done. My idea is to use a
Queue to add requests to and then have another process (thread) that will simply wait for the Queue to not be empty and then process requests one
at

a
time until it is empty and then again wait for the Queue to not be empty.
I'm looking for a basic framework of what would be best way to do this

using
what Classes and how to signal between threads (if needed?). I would use Queue, Thread? and ??

Any help is appreciated.

Norm




Jan 23 '06 #4
Thanks Mike, I will try that....

"Michael D. Ober" <obermd.@.alum.mit.edu.nospam> wrote in message
news:EP***************@newsread3.news.pas.earthlin k.net...
Justin,

In this case, create a new class that inherits from the Queue class.
Override the Enqueue (Add) and Dequeue (Remove) methods and put a synclock
around the actual add and remove methods of the queue class. This way
your
new class is thread safe.

I haven't used the Monitor.Enter/Monitor.Exit interface - SyncLock and
AutoResetEvents have been sufficient for my needs.

Mike.

"Justin" <justin23856 @ hotmail> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Mike,

Thanks for the input. However, that is exactly what I am doing now, and

I
do (now) care about the sequence of requests. That is why I was thinking

of
using the Queue class to hold requests. The main part I'm having trouble
with is in another thread processing those requests in the Queue and

letting
the thread that added the request to the queue know that its request has
been fulfilled. And, also how to make the Queue processing thread
'sleep'
until the Queue.count is > 0.

As an aside... I was wondering if you know the difference between using
SyncLock/End SyncLock and Monitor.Enter/Monitor.Exit?

Thanks again for any input!

Norm
"Michael D. Ober" <obermd.@.alum.mit.edu.nospam> wrote in message
news:St***************@newsread3.news.pas.earthlin k.net...
> Do you care about the order the requests are handled? If not, put your
> network handler in a module (class or regular) and then use the following > code around your "critical section"
>
> static SyncObj as new Object
> Synclock SyncObj
> ' Process Critical Section
> End SyncLock
>
> Note that SyncObj is static as it must stick around for the life of the
> application. What this does is stops all threads and forces them to wait > until the previous thread is complete with the network IO.
>
> Mike Ober.
>
> "Justin" <justin23856 @ hotmail> wrote in message
> news:e9**************@TK2MSFTNGP14.phx.gbl...
>> I am having trouble figuring out the best what to accomplish this fairly >> simple goal. I have a program that controls a 1-wire network and I
>> can
> only
>> make requests to it one at a time, but I will need to make new
>> requests
>> (from multiple threads) before the first one is done. My idea is to use >> a
>> Queue to add requests to and then have another process (thread) that will >> simply wait for the Queue to not be empty and then process requests
>> one
>> at
> a
>> time until it is empty and then again wait for the Queue to not be empty. >>
>> I'm looking for a basic framework of what would be best way to do this
> using
>> what Classes and how to signal between threads (if needed?). I would use >> Queue, Thread? and ??
>>
>> Any help is appreciated.
>>
>> Norm
>>
>>
>>
>
>
>



Jan 24 '06 #5

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

Similar topics

65
by: Anthony_Barker | last post by:
I have been reading a book about the evolution of the Basic programming language. The author states that Basic - particularly Microsoft's version is full of compromises which crept in along the...
19
by: Jane Austine | last post by:
As far as I know python's threading module models after Java's. However, I can't find something equivalent to Java's interrupt and isInterrupted methods, along with InterruptedException....
3
by: David Harrison | last post by:
I am working on an application on Mac OS X that calls out to python via PyImport_ImportModule(). I find that if the imported module creates and starts a python thread, the thread seems to be...
4
by: Antal Rutz | last post by:
Hi, All! I'm new to threading. I have some design questions: Task: I collect data and store them in an RDBMS (mysql or pgsql) The question is how to do that with threading? The...
6
by: CK | last post by:
I have the following code in a windows service, when I start the windows service process1 and process2 work fine , but final process (3) doesnt get called. i stop and restart the windows service...
7
by: Anthony Nystrom | last post by:
What is the correct way to stop a thread? abort? sleep? Will it start up again... Just curious... If the thread is enabling a form, if the form is disposed is the thread as well? Thanks, ...
4
by: Bob | last post by:
- For cleanup, is it sufficient to set a Thread to Nothing after it's done? - It is OK to pass objects out of the thread? (dumb question maybe but I want to be sure) - What's the best way to...
4
by: DBC User | last post by:
I have a background process which reads a table to see if there are any pending requests. If there are any, then it will start a worker thread (only 10 allowed at a time) and executes a method. In...
4
by: Steven | last post by:
I am taking an "advanced" VB.Net course via web at a state university toward an information science degree. This is my second VB class and I am kind of disappointed in it. This week we covered...
19
by: frankiespark | last post by:
Hello all, I was perusing the internet for information on threading when I came across this group. Since there seems to be a lot of good ideas and useful info I thought I'd pose a question. ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.