473,785 Members | 2,167 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Conceptualizing Threading

I have a multi-access problem that I'm pretty sure needs to be solved
with threading, but I'm not sure how to do it. This will be my first
foray into threading, so I'm a little confused by all of the new
landscape. So, I'm going to lay out the problem I'm facing and if
someone could point me towards a good example of what I need to do,
that would be great. I read THE tutorial, and while it made since to
me in an esoteric sense, I'm not sure how to implement it.

I have a program which will be logging who took what orders. These
orders need to have sequential order numbers. SR001001, SR001002,
SR001003, etc. Problem is I'm not sure how many people will be
accessing this program at the same time. I thought about separating
the order number into its own file and the having a function open it,
read it, increment it, write it, and close it really quick to limit
the chance of two people pulling the same number. Then I heard found
threading.

So this sounds like a consumer/producer problem, right? So I think I
need to use a Queue to crank out quote numbers and have the users
connect to the queue to get their number. Does that mean I'm looking
at two separate programs, a server and a client? Where do I separate
the programs? I was just about to give up and have quote number
assignment be manual (with error checking), but I thought I should
check here first and see if someone could help me wrap my brain around
this problem. You'll never learn if you never try, right?

Jun 21 '07 #1
2 965
You described how threads introduce a problem in your program -- that of
generating a sequence of sequential identifiers -- but you didn't describe
the problem that threads are solving in your program. Maybe you don't
need them at all? What led you to threading in the first place?

Jean-Paul
Well, the problem I thought they would solve is ensuring everyone got
a sequential number. But I suppose they wouldn't solve that, since
from what I gather thread access is somewhat arbitrary. So then, here
is the crux of the issue. Worst case scenario, this program could be
accessed by 5-10 people at a time and I need each one to have the
current information. There are two places I know of that there might
be multi-access problems.

1) This program is so that we can track one team passing assignments
to another. Right now I have the names of everyone in team 2 in a
list. People from team one launch this program and the program grabs a
pointer (stored in a separate file). If person A launches the program
and person B launches the program before person A assigns an order,
they will both have the same pointer, so both orders will go to the
same person.

2) Each assignment has a distinct identifier, which increments by 1
for each assignment (SR001001, SR001002, etc). Either these can be
assigned manually (the current method), or they can be assigned
automatically. If they are assigned manually, I need a way to show
them the most recent number (that would be easy), if they are assigned
automatically I need a way to save the number and pass the incremented
number along (just like the pointer). But I have the same problem here
as above. If two people launch the program at roughly the same time,
they will pull the same data. Since these assignments tend to come in
spurts, concurrent access is likely to be a problem.

So, given those parameters (the rest of this program is a breeze,
there's a class for each person on Team 2 and the class holds some
info about them and a dictionary of assignments with the assignment
number for the key and a value of [assigner, numberAssigned], the only
other tricky thing for me has been logging because I've never had to
do much of it before), how can I prevent these problems? The only
thing that jumps out at me is a server/client model where a server
runs and compiles all the entries, spitting back the result to each
individual client. That way, all the working code lives in the server,
ensuring that the working thread always has the right information,
while the clients only pass data between the user and the server. But
I guess that isn't technically multi-threading is it.

Jun 21 '07 #2
JonathanB wrote:
I have a multi-access problem that I'm pretty sure needs to be solved
with threading, but I'm not sure how to do it. This will be my first
foray into threading, so I'm a little confused by all of the new
landscape. So, I'm going to lay out the problem I'm facing and if
someone could point me towards a good example of what I need to do,
that would be great. I read THE tutorial, and while it made since to
me in an esoteric sense, I'm not sure how to implement it.

I have a program which will be logging who took what orders. These
orders need to have sequential order numbers. SR001001, SR001002,
SR001003, etc. Problem is I'm not sure how many people will be
accessing this program at the same time. I thought about separating
the order number into its own file and the having a function open it,
read it, increment it, write it, and close it really quick to limit
the chance of two people pulling the same number. Then I heard found
threading.

So this sounds like a consumer/producer problem, right? So I think I
need to use a Queue to crank out quote numbers and have the users
connect to the queue to get their number. Does that mean I'm looking
at two separate programs, a server and a client? Where do I separate
the programs? I was just about to give up and have quote number
assignment be manual (with error checking), but I thought I should
check here first and see if someone could help me wrap my brain around
this problem. You'll never learn if you never try, right?
Just use a database with an auto-incrementing column. It will handle all
the "threading" that you think you require and each call will return the next
number you need.

-Larry
Jun 21 '07 #3

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

Similar topics

65
6761
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 language's 30+ year evolution. What to you think python largest compromises are? The three that come to my mind are significant whitespace, dynamic typing, and that it is interpreted - not compiled. These three put python under fire and cause...
2
2990
by: Egor Bolonev | last post by:
hi all my program terminates with error i dont know why it tells 'TypeError: run() takes exactly 1 argument (10 given)' =program==================== import os, os.path, threading, sys def get_all_files(path): """return all files of folder path, scan with subfolders
77
5390
by: Jon Skeet [C# MVP] | last post by:
Please excuse the cross-post - I'm pretty sure I've had interest in the article on all the groups this is posted to. I've finally managed to finish my article on multi-threading - at least for the moment. I'd be *very* grateful if people with any interest in multi-threading would read it (even just bits of it - it's somewhat long to go through the whole thing!) to check for accuracy, effectiveness of examples, etc. Feel free to mail...
6
555
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 and the final process(3) gets called. what am I doing wrong with the threading? by the way Directory.GetFiles(IncomingXMLPath1).Length is some global outcome from process 1. Thanks 1)
2
2248
by: Vjay77 | last post by:
In this code: Private Sub downloadBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs) If Not (Me.downloadUrlTextBox.Text = "") Then Me.outputGroupBox.Enabled = True Me.bytesDownloadedTextBox.Text = "" Me.totalBytesTextBox.Text = ""
11
5040
by: Paul Sijben | last post by:
I am stumped by the following problem. I have a large multi-threaded server accepting communications on one UDP port (chosen for its supposed speed). I have been profiling the code and found that the UDP communication is my biggest drain on performance! Communication where the client and the server are on the same machine still takes 300ms or sometimes much more per packet on an Athlon64 3000+ running Linux (Fedora Core 5 x64). I must...
17
6433
by: OlafMeding | last post by:
Below are 2 files that isolate the problem. Note, both programs hang (stop responding) with hyper-threading turned on (a BIOS setting), but work as expected with hyper-threading turned off. Note, the Windows task manager shows 2 CPUs on the Performance tab with hyper-threading is turned on. Both Python 2.3.5 and 2.4.3 (downloaded from python.org) have this problem. The operating system is MS Windows XP Professional.
0
1596
by: kingcrowbar.list | last post by:
Hello Everyone I have been playing a little with pyGTK and threading to come up with simple alert dialog which plays a sound in the background. The need for threading came when in the first version i made, the gui would freeze after clicking the close button until pygame finished playing the sound. In Windows it was acceptable because it could be ignored easily, but in
7
2377
by: Mike P | last post by:
I am trying to write my first program using threading..basically I am moving messages from an Outlook inbox and want to show the user where the process is up to without having to wait until it has finished. I am trying to follow this example : http://www.codeproject.com/cs/miscctrl/progressdialog.asp But although the messages still get moved, the progress window never does anything. Here is my code in full, if anybody who knows...
0
9647
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
9489
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10356
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
10162
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10100
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9959
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
5396
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5528
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4061
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

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.