473,666 Members | 2,278 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Multi-thread, read/write to single file.

Multi-thread read/write to a single file.

I have two processing threads, thread A and thread B; and I called my
queue as Q.

Thread A will feed data into Q by user input, the timing is random.
Thread B will read data from Q to process; this processing will
communicate with a website.

I think the best Q architecture is ring buffer as large as possible.
However, my idea is to create a textbox.

The problem is the two threads might read/write to Q at the same time.
So, what I need to do is to suspend thread whenever user is submitting
data to Q?

How about when thread B is deleting data (because the data was
processed), I might need to suspend thread A, but thread A is user
interface, there should never a latency.

So, my idea is, UI should separate from processing thread.

Please give me any of your ideas.

Thanks!

Best regards,
Boki.

Jul 10 '07 #1
7 7258
It sounds like you are saying you have a class A that directly manipulates
the queue, as does class B, rather than both interacting through methods on a
class Q. I believe A and B should not care about the workings of Q. A
should simply call Add(xyz), while B should call Subtract() that returns the
next item (and pulls the data of the queue internally).

"Boki" wrote:
Multi-thread read/write to a single file.

I have two processing threads, thread A and thread B; and I called my
queue as Q.

Thread A will feed data into Q by user input, the timing is random.
Thread B will read data from Q to process; this processing will
communicate with a website.

I think the best Q architecture is ring buffer as large as possible.
However, my idea is to create a textbox.

The problem is the two threads might read/write to Q at the same time.
So, what I need to do is to suspend thread whenever user is submitting
data to Q?

How about when thread B is deleting data (because the data was
processed), I might need to suspend thread A, but thread A is user
interface, there should never a latency.

So, my idea is, UI should separate from processing thread.

Please give me any of your ideas.

Thanks!

Best regards,
Boki.

Jul 10 '07 #2
On Jul 10, 10:50 am, ModelBuilder
<ModelBuil...@d iscussions.micr osoft.comwrote:
It sounds like you are saying you have a class A that directly manipulates
the queue, as does class B, rather than both interacting through methods on a
class Q. I believe A and B should not care about the workings of Q. A
should simply call Add(xyz), while B should call Subtract() that returns the
next item (and pulls the data of the queue internally).

"Boki" wrote:
Multi-thread read/write to a single file.
I have two processing threads, thread A and thread B; and I called my
queue as Q.
Thread A will feed data into Q by user input, the timing is random.
Thread B will read data from Q to process; this processing will
communicate with a website.
I think the best Q architecture is ring buffer as large as possible.
However, my idea is to create a textbox.
The problem is the two threads might read/write to Q at the same time.
So, what I need to do is to suspend thread whenever user is submitting
data to Q?
How about when thread B is deleting data (because the data was
processed), I might need to suspend thread A, but thread A is user
interface, there should never a latency.
So, my idea is, UI should separate from processing thread.
Please give me any of your ideas.
Thanks!
Best regards,
Boki.
Ya, I just finished the code, and the result works well.

It sounds great, but I am confused, we don't need to consider the
conflict on reading/writing to a same file at the same time ?

Because I temporally test with a textbox ( however, it works well, but
I feel there is a automatically delay by windows OS, not my code
controlling ).

Speaking to the architecture, finally, I will implement to a real text
file on the storage, I think in the future, more threads ( maybe more
execution files ) are reading/writing to same file at the same time.

I think I might need to consider this issue (?)

Best regards,
Boki.

Jul 10 '07 #3
On Mon, 09 Jul 2007 20:01:42 -0700, Peter Duniho
<Np*********@nn owslpianmk.comw rote:
There are a variety of ways to do this. If one of the threads is the
main GUI thread, then you can use Control.Invoke( ) or
Control.BeginIn voke() from the other thread to add things to queue.
Addendum:

Of course, if the other thread is the one that removes things rather than
add things, then that would work fine too. The key is synchronizing
access by ensuring that all access happens on the same thread.
Jul 10 '07 #4
On Jul 10, 11:08 am, "Peter Duniho" <NpOeStPe...@nn owslpianmk.com>
wrote:
On Mon, 09 Jul 2007 20:01:42 -0700, Peter Duniho

<NpOeStPe...@nn owslpianmk.comw rote:
There are a variety of ways to do this. If one of the threads is the
main GUI thread, then you can use Control.Invoke( ) or
Control.BeginIn voke() from the other thread to add things to queue.

Addendum:

Of course, if the other thread is the one that removes things rather than
add things, then that would work fine too. The key is synchronizing
access by ensuring that all access happens on the same thread.
You are right, thanks a lot!

Best regards,
Boki.

Jul 10 '07 #5
Are you trying to store the state of the queue, or are you trying to use a
file to maintain the queue state?

"Boki" wrote:
On Jul 10, 10:50 am, ModelBuilder
<ModelBuil...@d iscussions.micr osoft.comwrote:
It sounds like you are saying you have a class A that directly manipulates
the queue, as does class B, rather than both interacting through methods on a
class Q. I believe A and B should not care about the workings of Q. A
should simply call Add(xyz), while B should call Subtract() that returns the
next item (and pulls the data of the queue internally).

"Boki" wrote:
Multi-thread read/write to a single file.
I have two processing threads, thread A and thread B; and I called my
queue as Q.
Thread A will feed data into Q by user input, the timing is random.
Thread B will read data from Q to process; this processing will
communicate with a website.
I think the best Q architecture is ring buffer as large as possible.
However, my idea is to create a textbox.
The problem is the two threads might read/write to Q at the same time.
So, what I need to do is to suspend thread whenever user is submitting
data to Q?
How about when thread B is deleting data (because the data was
processed), I might need to suspend thread A, but thread A is user
interface, there should never a latency.
So, my idea is, UI should separate from processing thread.
Please give me any of your ideas.
Thanks!
Best regards,
Boki.

Ya, I just finished the code, and the result works well.

It sounds great, but I am confused, we don't need to consider the
conflict on reading/writing to a same file at the same time ?

Because I temporally test with a textbox ( however, it works well, but
I feel there is a automatically delay by windows OS, not my code
controlling ).

Speaking to the architecture, finally, I will implement to a real text
file on the storage, I think in the future, more threads ( maybe more
execution files ) are reading/writing to same file at the same time.

I think I might need to consider this issue (?)

Best regards,
Boki.

Jul 10 '07 #6
Hi,

"Boki" <bo******@ms21. hinet.netwrote in message
news:11******** *************@x 35g2000prf.goog legroups.com...
Multi-thread read/write to a single file.

I have two processing threads, thread A and thread B; and I called my
queue as Q.
U mean that you are ACTUALLY using a queue right?
If that is so, use a synced queue (by using Queue.Synchroni zed(
yourQueue) ).
After that all the operations will be thread safe.

I think the best Q architecture is ring buffer as large as possible.
Humm, what about using your synced Queue?
However, my idea is to create a textbox.
You lost me here, what a textbox has to do with this?
The problem is the two threads might read/write to Q at the same time.
So, what I need to do is to suspend thread whenever user is submitting
data to Q?
If you use a sync'ed Queue the framework will take care of that for you.
How about when thread B is deleting data (because the data was
processed), I might need to suspend thread A, but thread A is user
interface, there should never a latency.
If you use a sync'ed Queue you can access it from both threads without any
problem.
Jul 10 '07 #7
On Jul 10, 11:26 pm, "Ignacio Machin \( .NET/ C# MVP \)" <machin TA
laceupsolutions .comwrote:
Hi,

"Boki" <bokit...@ms21. hinet.netwrote in message

news:11******** *************@x 35g2000prf.goog legroups.com...
Multi-thread read/write to a single file.
I have two processing threads, thread A and thread B; and I called my
queue as Q.

U mean that you are ACTUALLY using a queue right?
If that is so, use a synced queue (by using Queue.Synchroni zed(
yourQueue) ).
After that all the operations will be thread safe.
I think the best Q architecture is ring buffer as large as possible.

Humm, what about using your synced Queue?
However, my idea is to create a textbox.

You lost me here, what a textbox has to do with this?
The problem is the two threads might read/write to Q at the same time.
So, what I need to do is to suspend thread whenever user is submitting
data to Q?

If you use a sync'ed Queue the framework will take care of that for you.
How about when thread B is deleting data (because the data was
processed), I might need to suspend thread A, but thread A is user
interface, there should never a latency.

If you use a sync'ed Queue you can access it from both threads without any
problem.
Hi

I don't know this method before, I am checking it, thanks a lot!

Best regards,
Boki.

Jul 11 '07 #8

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

Similar topics

0
4923
by: Ganbold | last post by:
Hi, I'm new to multi-threaded programming and reading the book "Programming with POSIX Threads" and trying to understand concepts and coding. What I'm trying to do is to rewrite mysql client application (which calculates ISP dial-up customers' billing) into multi-threaded version.
12
3870
by: * ProteanThread * | last post by:
but depends upon the clique: http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&threadm=954drf%24oca%241%40agate.berkeley.edu&rnum=2&prev=/groups%3Fq%3D%2522cross%2Bposting%2Bversus%2Bmulti%2Bposting%2522%26ie%3DUTF-8%26oe%3DUTF-8%26hl%3Den ...
27
3268
by: DraguVaso | last post by:
Hi, The Multi column comboBox is a well spoken control, that a lot of people desire, and a lot of people buildtheir own. I tested a lot of them, but none really was what i wanted to have. But does anybody knows where I can find the best Multi column combobox? One that supports a lot of columns, possiblities to get the values in each column for the selected item, adding a DataSource etc... It should be free, and if possible with the...
6
4884
by: Joe | last post by:
I have 2 multi-list boxes, 1 displays course categories based on a table called CATEGORIES. This table has 2 fields CATEGORY_ID, CATEGORY_NAME The other multi-list box displays courses based on a table called COURSES. This table has 2 fields CATEGORY_ID, COURSE_NAME. The CATEGORY_ID is a FK in COURSES and a PK in CATEGORIES. I want to populate the course list box based on any category(s)
4
17857
by: mimmo | last post by:
Hi! I should convert the accented letters of a string in the correspondent letters not accented. But when I compile with -Wall it give me: warning: multi-character character constant Do the problem is the charset? How I can avoid this warning? But the worst thing isn't the warning, but that the program doesn't work! The program execute all other operations well, but it don't print the converted letters: for example, in the string...
6
11772
by: CindyH | last post by:
Hi Does anyone know how to create a multi column combo box from the same table? Thanks, Cindy
5
3273
by: dkelly925 | last post by:
Is there a way to add an If Statement to the following code so if data in a field equals "x" it will launch one report and if it equals "y" it would open another report. Anyone know how to modify this? Private Sub cmdPreview_Click() On Error GoTo Err_Handler 'Purpose: Open the report filtered to the items selected in the list box. 'Author: Allen J Browne, 2004. http://allenbrowne.com Dim varItem As Variant 'Selected items
23
5308
by: Kaz Kylheku | last post by:
I've been reading the recent cross-posted flamewar, and read Guido's article where he posits that embedding multi-line lambdas in expressions is an unsolvable puzzle. So for the last 15 minutes I applied myself to this problem and come up with this off-the-wall proposal for you people. Perhaps this idea has been proposed before, I don't know. The solutions I have seen all assume that the lambda must be completely inlined within the...
0
2320
by: Sabri.Pllana | last post by:
We apologize if you receive multiple copies of this call for papers. *********************************************************************** 2008 International Workshop on Multi-Core Computing Systems (MuCoCoS'08) Barcelona, Spain, March 4 - 7, 2008; in conjunction with CISIS'08. <http://www.par.univie.ac.at/~pllana/mucocos08> *********************************************************************** Context
11
5594
by: woodey2002 | last post by:
This problem is driving me crazy. Hello there, i am trying to create a search form for records in my access database. The search form will contain text boxes and a multi select list box. The user can enter their search criteria eg. surname, reg num, etc. in the text boxes. The multi select list box allows the user to select multiple counties which they have the option of including in the search. The user should be able to select or omit the...
0
8440
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8866
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8638
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7381
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6191
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4365
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2769
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2006
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1769
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.