Accueil > > > DISK FILLER MULTI THREADING
DISK FILLER MULTI THREADING
Information sur la source
Description
petit programme qui remplit un disque dur avec des fichiers pleins de zéros!
la partie graphique n'est pas extraordinaire mais c'est la premiere fois que je code un programme en multithreading.
Source
- #include <windows.h>
- #include <iostream>
- #include <conio.h>
- #include <iomanip>
- #include <string>
- #include <cmath>
- #include <fstream>
- using namespace std;
-
- //Header declarations
- long WINAPI WriteToDisk(int koko);
- void gotoxy(int x, int y );
- bool CheckIfAllFlase(void);
- double WrittenData[10];
- HANDLE hThread[10];
- DWORD dwID[10];
- DWORD dwRetVal = 0;
- long double TotalData_d;
- DWORD TotalThread;
- long double TotalDataByThread;
- long double ActualWrittenBytes;
- long double LastActualWrittenBytes;
- string TempData;
- long double SizeOfTempData = 20971520;
- bool started[10];
-
-
- int main(void){
- ActualWrittenBytes = 0;
- LastActualWrittenBytes = 0;
- //int DataByThread;
- cout << "What space would you want to fill in Bytes ( more than 1024 * number of Thread ):";
- cin >> TotalData_d;
- do{
- cout << "How much Thread will be running [1 to 10]:";
- cin >> TotalThread;
- }while(TotalThread >= 11 || TotalThread == 0);
- TotalDataByThread = ceil(TotalData_d / TotalThread);
-
-
- cout << endl << "Each Thread will have to generate " << setprecision(25) << TotalDataByThread << " Bytes of Data";
- cout << endl << endl << "Generating Temporary Data: 1 048 576 zeros... (1MB)";
- for(int i=0; i< 9; i++)
- started[i] = false;
- for(int i=1; i< SizeOfTempData+1; i++)
- TempData.insert(i-1,"0");
- cout << endl << endl << "Temporary Data Successfully created Are you Ready to fill your Disk?";
- cout << endl << "Press any key to continue or close this window";
- _getch();
-
- system("cls");
- cout << "Starting Processes...";
- cout << endl;
- for(int i=0; i < int(TotalThread); i++){
- hThread[i] = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)WriteToDisk,NULL,0,&dwID[i]);
- cout << "\t Thread #" << i+1 << " is running..." << endl;
- }
- do{
- gotoxy(0,0);
- ActualWrittenBytes = 0;
- for(int i=0; i< 9; i++)
- ActualWrittenBytes += WrittenData[i];
- //system("cls");
- cout << "Starting Processes..." << endl;
- for(int i=0; i< int(TotalThread); i++){
- cout << "\t Thread #" << i+1 << " is running...";
- cout << WrittenData[i] << " Bytes" << endl;
- }
- cout << endl << "Writing Speed : " << ceil((ActualWrittenBytes - LastActualWrittenBytes) / ( 1024) / (1024)) << " MB/s";
- cout << endl << "Progress : " << ceil((ActualWrittenBytes / TotalData_d) * 100) << "%";
- cout << endl << "Total Written Data : " << ceil(ActualWrittenBytes / 1024 / 1024) << " MB on " << ceil(TotalData_d /1024 /1024) << " MB";
- LastActualWrittenBytes = ActualWrittenBytes;
- Sleep(1000);
- }while(CheckIfAllFlase());
-
- for(int i=0; i< int(TotalThread); i++)
- CloseHandle(hThread[i]);
-
- cout << endl << endl << endl << "Work is Done!!!";
- _getch();
- return 0;
- }
-
- long WINAPI WriteToDisk(int koko){
- byte TH;
- TH=0;
- do{
- if(started[TH] == true)
- TH++;
- }while(started[TH] == true);
- started[TH]= true;
- WrittenData[TH] = 0;
- fstream myfile;
- string path = "E:\\";
- char ID_c[2];
- itoa(TH+1,ID_c,10);
- path.insert(3,ID_c);
- myfile.open( path.c_str());
- long double Repeat = ceil(TotalDataByThread / SizeOfTempData);
- for(int i=0; i < Repeat; i++){
- myfile << TempData;
- WrittenData[TH] += SizeOfTempData;
- }
- myfile.close();
- started[TH]= false;
- return 0;
- }
-
- void gotoxy(int x, int y ){
- COORD coord;
- coord.X = x;
- coord.Y = y;
- SetConsoleCursorPosition(
- GetStdHandle( STD_OUTPUT_HANDLE ),
- coord
- );
-
-
- }
-
- bool CheckIfAllFlase(void){
- for(int i=0; i< 9; i++){
- if(started[i]==true)
- return true;
- }
- return false;
- }
#include <windows.h>
#include <iostream>
#include <conio.h>
#include <iomanip>
#include <string>
#include <cmath>
#include <fstream>
using namespace std;
//Header declarations
long WINAPI WriteToDisk(int koko);
void gotoxy(int x, int y );
bool CheckIfAllFlase(void);
double WrittenData[10];
HANDLE hThread[10];
DWORD dwID[10];
DWORD dwRetVal = 0;
long double TotalData_d;
DWORD TotalThread;
long double TotalDataByThread;
long double ActualWrittenBytes;
long double LastActualWrittenBytes;
string TempData;
long double SizeOfTempData = 20971520;
bool started[10];
int main(void){
ActualWrittenBytes = 0;
LastActualWrittenBytes = 0;
//int DataByThread;
cout << "What space would you want to fill in Bytes ( more than 1024 * number of Thread ):";
cin >> TotalData_d;
do{
cout << "How much Thread will be running [1 to 10]:";
cin >> TotalThread;
}while(TotalThread >= 11 || TotalThread == 0);
TotalDataByThread = ceil(TotalData_d / TotalThread);
cout << endl << "Each Thread will have to generate " << setprecision(25) << TotalDataByThread << " Bytes of Data";
cout << endl << endl << "Generating Temporary Data: 1 048 576 zeros... (1MB)";
for(int i=0; i< 9; i++)
started[i] = false;
for(int i=1; i< SizeOfTempData+1; i++)
TempData.insert(i-1,"0");
cout << endl << endl << "Temporary Data Successfully created Are you Ready to fill your Disk?";
cout << endl << "Press any key to continue or close this window";
_getch();
system("cls");
cout << "Starting Processes...";
cout << endl;
for(int i=0; i < int(TotalThread); i++){
hThread[i] = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)WriteToDisk,NULL,0,&dwID[i]);
cout << "\t Thread #" << i+1 << " is running..." << endl;
}
do{
gotoxy(0,0);
ActualWrittenBytes = 0;
for(int i=0; i< 9; i++)
ActualWrittenBytes += WrittenData[i];
//system("cls");
cout << "Starting Processes..." << endl;
for(int i=0; i< int(TotalThread); i++){
cout << "\t Thread #" << i+1 << " is running...";
cout << WrittenData[i] << " Bytes" << endl;
}
cout << endl << "Writing Speed : " << ceil((ActualWrittenBytes - LastActualWrittenBytes) / ( 1024) / (1024)) << " MB/s";
cout << endl << "Progress : " << ceil((ActualWrittenBytes / TotalData_d) * 100) << "%";
cout << endl << "Total Written Data : " << ceil(ActualWrittenBytes / 1024 / 1024) << " MB on " << ceil(TotalData_d /1024 /1024) << " MB";
LastActualWrittenBytes = ActualWrittenBytes;
Sleep(1000);
}while(CheckIfAllFlase());
for(int i=0; i< int(TotalThread); i++)
CloseHandle(hThread[i]);
cout << endl << endl << endl << "Work is Done!!!";
_getch();
return 0;
}
long WINAPI WriteToDisk(int koko){
byte TH;
TH=0;
do{
if(started[TH] == true)
TH++;
}while(started[TH] == true);
started[TH]= true;
WrittenData[TH] = 0;
fstream myfile;
string path = "E:\\";
char ID_c[2];
itoa(TH+1,ID_c,10);
path.insert(3,ID_c);
myfile.open( path.c_str());
long double Repeat = ceil(TotalDataByThread / SizeOfTempData);
for(int i=0; i < Repeat; i++){
myfile << TempData;
WrittenData[TH] += SizeOfTempData;
}
myfile.close();
started[TH]= false;
return 0;
}
void gotoxy(int x, int y ){
COORD coord;
coord.X = x;
coord.Y = y;
SetConsoleCursorPosition(
GetStdHandle( STD_OUTPUT_HANDLE ),
coord
);
}
bool CheckIfAllFlase(void){
for(int i=0; i< 9; i++){
if(started[i]==true)
return true;
}
return false;
}
Conclusion
Des suggestion ou commentaire seront les bienvenus!
Historique
- 05 janvier 2009 04:40:09 :
- ajout capture...
Sources de la même categorie
Commentaires et avis
|
Derniers Blogs
[FRAMEWORK 4] LES TASKS ET LE THREAD UI[FRAMEWORK 4] LES TASKS ET LE THREAD UI par fathi
Je viens de passer quelques temps au TechDay's et j'ai pu voir pas mal de session intéressante. Par contre une chose m'a un peu étonné lors de certaines de ces sessions qui abordaient les améliorations du framework .NET (donc le 4.5) : en gros, bea...
Cliquez pour lire la suite de l'article par fathi WORKFLOW FOUNDATION 3 A UN PIED DANS LA TOMBEWORKFLOW FOUNDATION 3 A UN PIED DANS LA TOMBE par JeremyJeanson
Depuis déjà un an, je conseille vivement les utilisateurs de Workflow Foundation 3 à migrer vers la version 4. L'information qui va suivre ne devrait donc pas trop prendre au dépourvu les personnes qui m'ont suivi. Je profite de ce poste, pour faire le re...
Cliquez pour lire la suite de l'article par JeremyJeanson TECHDAYS PARIS 2012 : NOUVELLES TENDANCES DU POSTE DE TRAVAIL - BRING YOUR OWN PCTECHDAYS PARIS 2012 : NOUVELLES TENDANCES DU POSTE DE TRAVAIL - BRING YOUR OWN PC par ROMELARD Fabrice
Speakers: Thierry Rapatout, Antoine Petit et Xavier Trebbia Cette session entre dans le cadre des RDV Décideurs des TechDays 2012, elle est liée à la consumérisation de l'IT et la mise en place du "DeskTop as a Service" dans de plus en ...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice TECHDAYS PARIS 2012 : SYSTEM CENTER SERVICE MANAGER 2012 VUE D'ENSEMBLETECHDAYS PARIS 2012 : SYSTEM CENTER SERVICE MANAGER 2012 VUE D'ENSEMBLE par ROMELARD Fabrice
Speakers: Julien Marechal, Gautier Confiant, Sébastien MEYER La session débute par le positionnement de la solution System Center par rapport aux concepts d'organisation ITIL. Le portail du catalogue de se...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice TECHDAYS PARIS 2012 : PLEINIèRE SECOND JOURTECHDAYS PARIS 2012 : PLEINIèRE SECOND JOUR par ROMELARD Fabrice
Après une première journée dédiée aux développeurs, cette seconde journée est dédiée au monde des entreprises et de ses applications. Ainsi, cette pleinière est dédiée à faire un 360 de l'évolution des applications Business aux demandes ac...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice
Logiciels
Academy System (17.2.1.0)ACADEMY SYSTEM (17.2.1.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System Easy-Planning (1.0.0.1)EASY-PLANNING (1.0.0.1)Basé sur les mêmes principes que MyPlanning, Easy-Planning permet de créer des plannings sous la ... Cliquez pour télécharger Easy-Planning COLLECTOR PLUS (3.00B)COLLECTOR PLUS (3.00B)COLLECTOR PLUS version 3.00B est un logiciel utilisant une base de données alimentée par :
- L... Cliquez pour télécharger COLLECTOR PLUS PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V7.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V7.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO LettresFaciles 2011 (8.0.0.1)LETTRESFACILES 2011 (8.0.0.1)LettresFaciles est un logiciel facilitant la création et la rédaction de lettres types.
Son inte... Cliquez pour télécharger LettresFaciles 2011
|