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

Should I use threads when an event is filling a buffer?

I am modifying some code that uses 'events' to add to a buffer.
Suppose I want to write a routine that will read from the buffer at
timed intervals. Is there a danger that when I read from the buffer,
an event will suddenly be raised in the middle of my read, and that
event will modify the buffer?
And would using threads prevent this?
Thanks,
-- HA
Note: My read actually should remove info from the buffer as it reads
- so its modifying the buffer.

Mar 6 '07 #1
3 1125
On Mar 6, 1:47 pm, HONOREDANCES...@YAHOO.COM wrote:
I am modifying some code that uses 'events' to add to a buffer.
Suppose I want to write a routine that will read from the buffer at
timed intervals. Is there a danger that when I read from the buffer,
an event will suddenly be raised in the middle of my read, and that
event will modify the buffer?
And would using threads prevent this?
Thanks,
-- HA
Note: My read actually should remove info from the buffer as it reads
- so its modifying the buffer.
Your question is difficult to give a straight answer to. You see,
events are really methods and are usually executed on the same thread
that they are raised on (this can be changed by using an async
delegate). So, your question depends on the architecture of you
application. Are you using threads? ThreadPool? Async delegates?
The system.windows.forms.timer is single threaded, but other timers
are not.

Basically, more info is needed to really give complete answer....

--
Tom Shelton

Mar 7 '07 #2
Hi,

To add a little bit to Tom, multithreading is only possible if there are
parallel processes.

If your application has to wait until the buffer is filled than
multithreading can only be to keep the closing box etc going.

I am working now on a very large project and sometimes I wish that Visual
Studio had the feature to stop while loading, however I am glad it is not
there, mostly it is only a subject for bugs.

The latter just my thought,

Cor

<HO*************@YAHOO.COMschreef in bericht
news:11*********************@q40g2000cwq.googlegro ups.com...
>I am modifying some code that uses 'events' to add to a buffer.
Suppose I want to write a routine that will read from the buffer at
timed intervals. Is there a danger that when I read from the buffer,
an event will suddenly be raised in the middle of my read, and that
event will modify the buffer?
And would using threads prevent this?
Thanks,
-- HA
Note: My read actually should remove info from the buffer as it reads
- so its modifying the buffer.

Mar 7 '07 #3
On Mar 6, 1:47 pm, HA wrote:
I am modifying some code that uses 'events' to add to a buffer.
Suppose I want to write a routine that will read from the buffer at
timed intervals. Is there a danger that when I read from the buffer,
an event will suddenly be raised in the middle of my read, and that
event will modify the buffer?
And would usingthreadsprevent this?
Thanks,
-- HA
Note: My read actually should remove info from the buffer as it reads
- so its modifying the buffer.
Tom Shelton Answers:
Your question is difficult to give a straight answer to. You see,
events are really methods and are usually executed on the same thread
that they are raised on (this can be changed by using an async
delegate). So, your question depends on the architecture of you
application. Are you usingthreads? ThreadPool? Async delegates?
The system.windows.forms.timer is single threaded, but other timers
are not.
The events are be raised by some other dll, but I have a program that
calls the dll and so the events are in that program. I put a MSGBOX
in one of the events, and then ran the program, and I thought that the
program would stop at the MSGBOX until I hit OK. But thats not what
happened. Msgboxes kept coming up until the screen was full of them,
and then the program crashed. In other words, when the event stopped
at the msgbox, waiting for my input, the event was called again and
again, each time putting up more msgboxes. This suggests that I
really do have to worry about code interrupting other code.
The event is supposed to put some information from its arguments into
a buffer. I also want another routine that will empty buffer. But if
the event can interrupt itself, it should be able to interrupt the
routine as well. So maybe threads are needed. What do you think?
Mar 8 '07 #4

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

Similar topics

1
by: Leif K-Brooks | last post by:
I'm considering writing a fairly basic vector drawing program using PyGTK. What's the best way to render it? What I'm thinking of is having everything render on a PIL image, then display that in...
58
by: Jeff_Relf | last post by:
Hi Tom, You showed: << private const string PHONE_LIST = "495.1000__424.1111___(206)564-5555_1.800.325.3333"; static void Main( string args ) { foreach (string phoneNumber in Regex.Split...
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) {}
5
by: Leonardo Hyppolito | last post by:
Hello! I am trying to implement a program that uses Threads. I chose the producers and consumers scenario. The producers put a "product" (which is an int number) in a shared storage place of one...
3
by: Stampede | last post by:
Hi, I want to use the FileSystemWatcher in a Windows Service. I read an article, where the author created the FileSystemWatcher object in a seperate thread and when the event is fired, he started...
7
by: =?Utf-8?B?Q2hyaXM=?= | last post by:
I have a win app. this a form with a button. after pressing the button a new form is shown. when looading the form is being filled by data taken from a database. the problem is that it takes a few...
1
by: jopeter | last post by:
hi i have wrote this progaram in java. it finf the palidrome numbers and print it. its by threads it has some errors and i can t run it. please help me. package palindromen; import...
4
by: christian.siegl | last post by:
Hello, I need a buffer reinitialized approx. once in each second (I think this is quite often). Now I think to do the reinit within a separate thread (I am using boost::thread). Well, filling...
1
by: shapirlex | last post by:
Hello, I'd like to fill a buffer with different type on variables (i.e. integers, strings..). I have a pointer to pointer data structure (char **array_of_indexed_buffers) that initialized as...
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: 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
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: 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.