|
Thanks Mark.
Using a thread in our application will probably be overkill and not necessary, but I'm using the opportunity to learn a little bit on the side; Thread is one of the things I never really coded (was done by other people before).
BTW, the Sleep will not be in the final code! I will replace that with real functional code.
Still learning.
|
|
|
|
|
Hi,
- I use VC++ 6.0 in Win2k. I want built app to communication through USB port. How to start ?
Quang,
|
|
|
|
|
|
I have a CDialogBar which has a few CButton objects in it. Each CButton object contains an icon (no text) and I'd like them to appear like the buttons in a CToolBar do (flat, not raised, until the mouse hovers over the button). I used Spy++ to look at the button styles of the buttons in the tool bar, but only the tool bar has a hwnd - none of the buttons do, so it looks like the tool bar might be owner-drawing the buttons itself.
Is there a known set of button styles/window styles that one can set a CButton to and get it to appear like a button within a CToolBar does?
I can always look and see if someone has built an owner drawn CButton class which emulates a CToolBar button, but if this functionality is already built into the system then I'd rather use what's already here.
Thanks,
Jeff
|
|
|
|
|
|
Hay hi Guys
i have a single processor in my system and in my application i create more then 1 thread, so does it enhance my application, as at a given point of time only instruction can be executed, how does it make difference, does it speed up my application,
for example
i am retrieving 500 web logs from a site,
so if i create 10 threads in one go and in each thread i retrieve 1 log
i have to make 50 calls at go which will fetch those 500 logs,
so will it speed up the downloading or fetching up the logs
or should i go with application thread which will fetch 1 by 1,
which method will be useful...........
or any idea or implimentaion idea..........
i am not concerned about the server bandwidth or speed of my processor, my Question is doing the repetitive work in one thread at a time with multiple time is faster or doing it in multiple threads is faster . P.S. not concerned about UI too
thread t{ print 1;} /1st time
..
thread t{ print 1;}/100th time
OR
thread {t0,t1,t2,t3,t4,t5,t6,t7,t8,t9}{print 1;}/1st 10 run
..
thread {t0,t1,t2,t3,t4,t5,t6,t7,t8,t9}{print 1;}/last 10run=100
which will complete faster
Thanks
Swarup
modified on Tuesday, February 19, 2008 5:12 PM
|
|
|
|
|
It can helps if you need to have your application front-end no locked up because of some code.
for example, you have a UI that launch your log fetching thing, if you do that in a loop (in the default single thread), the UI will be locked until the loop is over.
But if you start the fetching thing in a different thread, then your UI will still be alive.
When you are dealing with concurrent connection, theoretically yes, it can increase the performance, but in practice, you will have some limitations due to the number of connections allowed, the bottleneck of your connection speed, ...
|
|
|
|
|
Thank you, but i am nt concerned bout UI part, becas i am handling UI in dif thread, i agree about UI, But what i am talking is, executing 100 threads is better or executing 1 thread is better.
example
1 thread called 100 times to do the same work (same work each time) OR
10 threas called 10 times to do the same work (same work each time), which method is faster, which method will complete faster, thats wht i am asking.............
Thanks again for ur reply......
thread t{ print 1;} /1st time
..
thread t{ print 1;}/100th time
OR
thread {t0,t1,t2,t3,t4,t5,t6,t7,t8,t9}{print 1;}/1st 10 run
..
thread {t0,t1,t2,t3,t4,t5,t6,t7,t8,t9}{print 1;}/last 10run=100
which will complete faster
Swarup
|
|
|
|
|
swarup wrote: is, executing 100 threads is better or executing 1 thread is better.
That depends on what each thread is doing.
swarup wrote: 1 thread called 100 times to do the same work (same work each time) OR
10 threas called 10 times to do the same work (same work each time), which method is faster, which method will complete faster
Neither will be faster than the other. On a single processor system, executing the same code 100 times, no matter how many threads you use to run the code will not execute any faster. If the code is 1,000 instructions, start-to-finish, the processor has to execute 1,000,000 instructions to get the job done. Since a single proc can only execute one instruction at a time, it doesn't matter how many threads you use, it's still 1,000,000 instructions to execute, one at a time.
Now, if you have multiple processors, the CPU can start executing more than one instruction at the same time. The process CAN run faster, but in no way is this guaranteed. It depends on what this code, that your executing 100 times, is doing and how it affects the CPU, memory controller, caching, I/O, ..., ...
swarup wrote: thread t{ print 1;} /1st time
..
thread t{ print 1;}/100th time
OR
thread {t0,t1,t2,t3,t4,t5,t6,t7,t8,t9}{print 1;}/1st 10 run
..
thread {t0,t1,t2,t3,t4,t5,t6,t7,t8,t9}{print 1;}/last 10run=100
which will complete faster
On a single core CPU, neither. You seem to have the misconception in your head that more threads = faster performance. Nothing could be further from the truth. Threading is a logical division of work, not a replacement for faster processing.
|
|
|
|
|
That depends entirely on the Server you are requesting from. If any of those requests will block at the same time that others won't then threads or even Overlapped I/O can, if done reasonably, reduce the total time to receive all 500 items.
led mike
|
|
|
|
|
Thanks a lot,
i am not concerned about the server bandwidth or speed of my processor, my Question is doing the repetative work in one thread multiple time is faster or doing it in multiple threads is faster . P.S. not concerned about UI too
|
|
|
|
|
swarup wrote: i am not concerned about the server bandwidth
swarup wrote: my Question is doing the repetative work in one thread multiple time is faster or doing it in multiple threads is faster
Let me try to make my point a different way. If you had to do the same thing but all 500 files were on your local hard drive you would likely slow down overall processing by using more than a single thread to open and read the files into memory. Would it be measurable? Likely? Noticeable? Don't know.
This is why the only thing that matters significantly is the Server. Of course if you can't depend on Server response being consistent at the various times you will be doing this you would have to develop algorithms to modify the approach dynamically based on Server response.
So now what are you going to do?
led mike
|
|
|
|
|
Hi Mike
No i dont think so,
take a scenario::
<br />
main()<br />
{<br />
thread t;<br />
for(i 0 to 100)<br />
{time = t.callme();}<br />
thread t[10];<br />
for(i 0 to 10)<br />
{t[i].callme();}<br />
loop another 10 times more<br />
}<br />
<br />
callme()<br />
{<br />
u called me,finished in 1 sec;}<br />
thanks
Swarup
|
|
|
|
|
swarup wrote: No i dont think so,
Whatever, I'm done.
led mike
|
|
|
|
|
swarup wrote: ...so does it enhance my application...
Highly doubtful, since all of the context switching would slow it down.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
It really depends on what you are doing in the threads. Take your example, you have 100 log files to retrieve and process. Perhaps the time to retrieve a single log file would be about 0.5 seconds, then you do some processing, perhaps search a database, which may take anywhere between 0.1 and 10 seconds, then yes, using several threads would increase the speed. In this case, while one thread does a ten second search, another thread may complete 10 1 second searches.
But, if the time is pretty much standard for each log file, then as David Crow said, the constant switching between threads will take away any performance gain.
Waldermort
|
|
|
|
|
Hi
First of all I should say, I dont want to bother any one with my question or long program
please if you have time, help me.( I dont mean that I want any one to do my program, just please if you are an expert and professional in C++, please help me and guid me how to fix the program)
I did my best to comment my program.
I am learning C++ and now I'm working on a program that:
reads in a file "customers.txt" containing the information for bank customers. The file is formatted with each customer's name, arrival time (in minutes after 9:00), and service time (in minutes) on a separate line. The program moves each customer into the bank line at the arrival time. If the teller counter is available, the customer is moved out of the line to the teller. When the customer has spent the specified amount of time at the counter, they leave the bank and the next customer steps up. The program continues until all customers are serviced.
I'm trying to make Multiple Tellers, at this time my program assumes the bank has only one teller/counter. I want to modify the program so that it can handle multiple tellers, so that the customers in line will move to any available teller. For example, "Chewbacca steps up to counter #2" or "Vader has left counter #4."
but I have no idea how I can do that:
right now my program works, but I dont know how to add multiple tellers.
my program is:
Code: ( cpp )
/************************************************** **
** The main routine simulates a line-up at the bank.
************************************************** ***/
int main() {
//Read in the customer file.
//Assume file is in format: Name ArrivalTime ServiceTime
//Assume list is sorted based on distinct arrival times.
string file_name; // the files name that user input
ifstream fin;
cout<<"please Enter your choice:\nChoice1: (You can type in the name of your file.)\nchoice2: (You can ask the program to generate a list of random customers.)\n\n";
int choice;
cout<<"what is your choice? (1 or 2):";
cin>>choice;
while(choice!=1 && choice!=2){
cout<<"You should type 1 or 2, try again:\nEnter you choice again:";
cin>>choice;
}
Queue<Customer> customerList;
Customer newCustomer;
if(choice==1){ //choice 1 , user type his/her file_name to open
cout<<"PLease type your file name:";
cin >> file_name;
cout<<"\n";
fin.open( file_name.c_str( ) );
while (fin >> newCustomer)
customerList.enter(newCustomer);
fin.close();
if (customerList.isEmpty()) {
cout << "Could not read file customers.txt.\n";
return 0;
}
}
if (choice==2){
cout<<"Please specify the probability that a customer arrives each minute:";
int probability;
cin>>probability;
for (int i=0; i <= 540; i++) {
if ( 1+rand()%100 <= probability )
customerList.enter( Customer("A customer", i, 5+rand()%11) );
}
}
int num_teller; //number of tellers
cout<<"please Enter the Number of tellers:";
cin>>num_teller;
cout<<"\n";
//The first customer immediately steps up to the counter, no waiting.
//We start the clock running at first customer's arrival time.
Customer atCounter = customerList.leave();
bool isCounterEmpty = false;
int currentTime = atCounter.get_arrivalTime();
int startService = atCounter.get_arrivalTime();
printTime(currentTime);
cout << " " << atCounter.get_name() << " has entered the bank.\n";
printTime(currentTime);
cout << " " << atCounter.get_name() << " stepped up to the counter.\n";
//Set up our empty line.
Queue<Customer> line;
//Repeat while there are customers in bank or yet to arrive.
while (!customerList.isEmpty() || !line.isEmpty() || !isCounterEmpty) {
//Check if someone enters line.
if (!customerList.isEmpty() && (customerList.peek()).get_arrivalTime() <= currentTime) {
printTime(currentTime);
cout << " "<< (customerList.peek()).get_name()
<< " has entered the bank.\n";
line.enter( customerList.leave() );
}
//Check if someone leaves the counter.
if ( !isCounterEmpty && (startService + atCounter.get_serviceTime() <= currentTime) ) {
isCounterEmpty = true;
printTime(currentTime);
cout << " "
<< atCounter.get_name()
<< " has left the counter.\n";
}
//Check if counter is empty and someone is waiting in line.
if ( isCounterEmpty && !line.isEmpty() ) {
atCounter = line.leave();
startService = currentTime;
isCounterEmpty = false;
printTime(currentTime);
cout << " " << atCounter.get_name()
<< " has stepped up to the counter.\n";
}
currentTime++; //Inefficient. Better to move to next event time.
}
//Compute queue statistics.
return 0;
}
|
|
|
|
|
apejman wrote: I'm trying to make Multiple Tellers, at this time my program assumes the bank has only one teller/counter. I want to modify the program so that it can handle multiple tellers, so that the customers in line will move to any available teller. For example, "Chewbacca steps up to counter #2" or "Vader has left counter #4."
but I have no idea how I can do that:
right now my program works, but I dont know how to add multiple tellers.
I would create an object to represent the set of tellers. Your IsCounterEmpty variable would be replaced by AreAllCountersFull, and AreAllCountersEmpty propertys. When checking for a customer finishing service, you would either loop over the counters in your main function, or provide a member of the teller set that does the looping and removing. When adding a customer, you the teller set could provide a method that would assign a customer to the first available teller.
Nathan
|
|
|
|
|
hi,
i've got a regular dll project with mfc support. project has a dialog resource and a class for that dialog, say CMyDialog. an exported global function of the project shows the dialog by "DoModal"ing it when called.
the problem is, when i put an activex control on the dialog and bind it to a member object(which is an instance of the auto-generated class of that activex control) of CMyDialog, it doesn't show up.
i read the related msdn article(knowledge base Q231591: How To Use a Dialog Template to Create a MFC Dialog with an ActiveX Control) but couldn't figure out how to use it.
another thing which is strange but unrelated to problem above is that, if i don't leave the OnInitdialog function empty and put an afxmessagebox line, the dialog becomes modeless even if i DoModal it. it's not a problem and even something good for me. but i just wanted to know why.
any suggestions, solutions?
thanks.
|
|
|
|
|
The problem is that I used BCGPro and when docking two views together the parent wnd changed to a tabbed wnd which is introduced by BCGPro.
-----------------------------------------------------------------
I have a VC6 project which can be compiled and run.
After I copy the project to a new computer (CPU is AMD 4000+), it report runtime error, when using dynamic_cast (not each, some are right).
Is it the fault of the code?
How to solve it? Will using vs2005 help?
Thanks a lot.
PS: the cpu is already patched
modified on Thursday, February 21, 2008 10:21 PM
|
|
|
|
|
followait wrote: it report runtime error,
who/what is "it" ? the compiler ? the execution of the program ?
Are you using the same version of Visual Studio ?
Are any patch installed on one machine and not the other ?
Are the project settings the same ? have you enable/disabled the RTTI in the project?
...
|
|
|
|
|
"it" is the executive.
All is the same, except hardware.
|
|
|
|
|
most probably a coding error.
|
|
|
|
|
It is so simple, and according to my experience, it should be right.
I've no experience with a dual core cpu.
|
|
|
|
|
followait wrote: I've no experience with a dual core cpu.
I guess it has nothing related with dual-core.
How do you use that dynamic_cast ? Do you mind showing some code snippet?
Maxwell Chen
|
|
|
|
|