|
I;d question your design decision as desiribed, but I'll assume your simplifying your actual problem.
Thread handles also act as signalling handles.
So:
....
HANDLE hThread [MAX] = { NULL, NULL, ... NULL };
DWORD dwID [MAX];
for (nTest = 0; nTest < 10; nTest++)
{
hThread [nTest] = CreateThread (......., &(dwID [nTest], lParam);
if (!hThread [nTest])
{
Handle error somehow
}
}
for (nTest = 10; nTest < XXXXX; nTest++)
{
dwWait = WaitForMultipleObjects (hThread, 10, INFINITE);
if (dwWait >= WAIT_OBJECT_0 && dwWait < WAIT_OBJECT_0+10)
{
nThread = dwWait - WAIT_OBJECT_0;
hThread [dwThread] = CreateThread (......., &(dwID [nThread], lParam);
if (!hThread [nTest])
{
Handle error somehow
}
}
}
/pre>
Tada!
Iain.
<div class="CPhogPost"></div>
<div class="ForumSig"></div>
|
|
|
|
|
I would also point out that I have answered your question very literally. My answer would block your initial thread, is very fragile, etc.
Much better would be to look into thread pools (which I have no experience of), of have your thread posting a "I'm done!" message to a UI main thread, which would then fire off another thread. You could then give the user a more interactive experience, without thinking the process has hung. It would also allow you to handle failure more gracefully.
Iain.
|
|
|
|
|
You can use a variable to count the threads
Global declaration:
<code>volatile </code>UINT RunningThread;
The main function:
foo(){
RunningThread=0;
for(i=0;i<200;i++){
if(RunningThread<10){
RunningThread++;
}else{
wait(100);
i--;
continue;
}
}
}
The thread:
Thread(...){
RunningThread--;
}
Russell
|
|
|
|
|
i tried Russell's procedure but its hanging my application and not solving my problem completely....in my thread i m finding out a particular website's html code so, because of so many threads trying to do it, many times it gives page cannot be displayed....how to solve it
|
|
|
|
|
Probally you have to use a semaphore to use the connection in a more efficient way, limiting the simultaneus request to the web.
You can use for example a boolean variable (like BOOL ConnectionIsBusy ). If a thread find it TRUE then it waits that it becomes FALSE , then it lock itself the flag to TRUE , talk with the web, and at the end restore the flag value to FALSE .
A similar way is to limit the number of simultaneus connections using a variable like UINT ConnectionsNumber , that you could use to check that the connection opened are less of a particular value (i.e. 2 or 4).
But the problem depends also on the speed of your connection and/or the amount of traffic that you need to exchange with the web. You have to do some tests.
Russell
|
|
|
|
|
Another way to implement Russell's suggestion is to use an I/O Completion Port[^]
This essentially combines a thread pool with a semaphore. With an I/O Completion Port you could
easily create a pool of 10 threads and queue up 200 operations to be executed by the threads as
they become available.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hello
I am VS 2005 for the first time. I have selected a Dialog based application which uses MFC and I want to add a WM_INITDIALOG message handler. We use "Ctrl + W" for VC 6 to invoke class wizard and add a message handler for WM_INITDIALOG.
But in VS 2005, I selected properties of the dialog and looked under the "Messages" tab and dint find the WM_INITDIALOG message to add a handler for that. Do should I do this in VS 2005 ?
Thanx
|
|
|
|
|
Add a class for the dialog if not added.
Go to Class view, Right click that class, go to property, then you will find all the virtual functions in the 3rd tab.
Anurag Gandhi.
http://www.softgandhi.co.nr
|
|
|
|
|
I still miss the Class wizzard with its "Ctrl+W" feature.
IMHO this is a sign how carefully sometimes the job is done in the big M$-code machine
Greetings from Germany
|
|
|
|
|
Hello All,
i have to find Partition name like(New Volume(K ) but by using partition number because i am having PARTITION_INFORMATION structure in the project.
now i am unable to get PArtition Name by using Partition Number.
if you have any idea about this please please share with me.
thanks
bankey
|
|
|
|
|
the volume name can be found out from the from GetVolumeInformation(). This function requires the drive letter not the partion number.If you manage to get the drive letter, you can get the volume name.
If there is no staright way for doing this, you can use the below method.
You can use the QueryDosDevice() function to find the diive letter from parition name. for eg consider the below code. If 'c' is the first partion, the tcDeviceName will contain \Device\HarddiskVolume1. and if you give 'd:', it will be \Device\HarddiskVolume2 and so on
TCHAR tcDeviceName[50];
QueryDosDevice( _T("C:"), tcDeviceName, 50 );
suppose you got 1 in the PARTITION_INFORMATION. then make string like "\Device\HarddiskVolume1". Now starting from A to Z, put a loop and call the QueryDosDevice. Compare the device name with the "\Device\HarddiskVolume1". If it matches, you have the drive letter.
|
|
|
|
|
Hello there!
i work in VC++ and i want to write an asm code in my code
in this code, i want to write an interrupt,
i don't know list of interrupts in windows system???
I'd like to know how I can find the IDT addresses?
how do i access to this address (IDT) and how do i change address of an interrupt? (whit assembly code)
Zo.Naderi-Iran
|
|
|
|
|
zon_cpp wrote: list of interrupts in windows system
See here[^] does helpful?
|
|
|
|
|
hi
how can i control the sound of left and right speaker by vc++/mfc.Actually i want to send different sound at same time on left and right speaker.
if anybody reply me i will obliged
malik
|
|
|
|
|
See MIXERCONTROLDETAILS does your answer?
|
|
|
|
|
Hello
In my current project, I am using an .ini file to store information related to the application, such as windows start up position, critical information, file paths etc. This .ini file will be easily readable and editable.
Is there a way other than .ini file and "registry" where in the applicaiton information can be stored and used in between applicaiton sesstions.
Thanx
|
|
|
|
|
You can dream up your own file format and manage your settings files yourself. If you do so, make sure to put the files in the %APPDATA% folder.
The registry isn't that glamorous, but it's easy to use, it's secure, and it works.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
<A HREF="http://www.soonr.com">SoonR Inc -- PC Power delivered to your phone</A>
|
|
|
|
|
vipin_nvk wrote: Is there a way other than .ini file and "registry" where in the applicaiton information can be stored and used in between applicaiton sesstions.
An XML file, for instance.
If you're using MFC, and you application is truly OO, then have a look at MFC Serialization http://msdn2.microsoft.com/en-us/library/6bz744w8(VS.80).aspx[^], a quite powerful tecnique.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
|
why do you care the files are readable ? if the users modify it, it's their problem, not yours
|
|
|
|
|
The purpose of .ini file is to facilitate the user to change environment settings, with out rebuilding the application.
I don't understand what security threat you will have until and unless some passwords are present in .ini file. Anyways password can also be encripted and stored in .ini file.
|
|
|
|
|
i'm not the OP... are you sure you wanted to say that to me ?
|
|
|
|
|
nope. that reply was not intended to you Mr toxcct. Actually I am suporting all your suggestions, adding mine at the same time.
I know what will happen being rude to some one like you, senior member of this DB
|
|
|
|
|
You are right toxcct.
Well, no one (I am talking about non-stupid guy) is editing the Registry information unless it is clearly known to him that what exactly he is doing. Or they are taking the backup of the registry before editing.
About readability, configuration setting is not a NASA project that needs to be so secure.
Anurag Gandhi.
http://www.softgandhi.co.nr
|
|
|
|
|
Whatever you are doing, ultimately you are saving the information in the hard disk in one way or the other.
I may be a Registry Database, Sql server database, an XML file, a text file format or ini file.
I will suggest use windows registry because it is very easy to use. Don't waste your time and energy in thinking about these logics unless your requirement is completely different and registry can't serve the purpose.
Anurag Gandhi.
http://www.softgandhi.co.nr
|
|
|
|