@@ -117,68 +117,62 @@ int main (int argc, char* argv[])
117117cout << "THR " << (unsigned long)current << " PRIORITY : " << param.__sched_priority << " POLICY : " << policy << endl; */
118118 try
119119 {
120- const size_t nbProcs = MachineData::instance ( ).getProcessorsNum ( );
121-
122- cout << " Computer " << NetworkData::getCurrentHostName ( ) << " has "
123- << nbProcs << " processors." << endl;
124-
125- vector <JoinableThread*> tasks;
126- size_t i = 0 ;
127- const size_t max = 10 ;
128- Writer writer (stdout);
129- cout << " Creation of " << (unsigned long )max
130- << " joinable writing tasks without mutex ..." << endl;
131- for (i = 0 ; i < max; i++)
132- tasks.push_back (new WriterThread (max, writer));
133- cout << " Running tasks ..." << endl;
134- for (i = 0 ; i < max; i++)
135- tasks [i]->startTask ( );
136- // Rem : sched_yield important, on peut sinon observer des plantages,
137- // probablement à cause de tâches qui ne se sont pas encore lancées.
138- sched_yield ( );
139- cout << " Joining tasks ..." << endl;
140- for (i = 0 ; i < max; i++)
141- {
142- tasks [i]->join ( );
143- }
144- cout << " Joinable writing tasks without mutex completed." << endl;
145- cout << " Deleting tasks ..." << endl;
146- for (i = 0 ; i < max; i++)
147- delete tasks [i];
148- cout << endl << endl;
149-
150- tasks.clear ( );
151- ProtectedWriter pwriter (stdout);
152- cout << " Creation of " << (unsigned long )max
153- << " joinable writing tasks with mutexes ..." << endl;
154- for (i = 0 ; i < max; i++)
155- tasks.push_back (new WriterThread (max, pwriter));
156- cout << " Running tasks ..." << endl;
157- for (i = 0 ; i < max; i++)
158- tasks [i]->startTask ( );
159- sched_yield ( );
160- cout << " Joining tasks ..." << endl;
161- for (i = 0 ; i < max; i++)
162- {
163- tasks [i]->join ( );
164- // delete tasks [i];
165- cout << " Deleting tasks." << endl;
166- }
167- for (i = 0 ; i < max; i++)
168- {
169- delete tasks [i];
170- }
171- cout << " Joinable writing tasks with mutexes completed." << endl;
120+
121+ const size_t nbProcs = MachineData::instance ( ).getProcessorsNum ( );
122+
123+ cout << " Computer " << NetworkData::getCurrentHostName ( ) << " has " << nbProcs << " processors." << endl;
124+
125+ vector <JoinableThread*> tasks;
126+ size_t i = 0 ;
127+ const size_t max = 10 ;
128+ Writer writer (stdout);
129+ cout << " Creation of " << (unsigned long )max << " joinable writing tasks without mutex ..." << endl;
130+ for (i = 0 ; i < max; i++)
131+ tasks.push_back (new WriterThread (max, writer));
132+ cout << " Running tasks ..." << endl;
133+ for (i = 0 ; i < max; i++)
134+ tasks [i]->startTask ( );
135+ // Rem : sched_yield important, on peut sinon observer des plantages, probablement à cause de tâches qui ne se sont pas encore lancées.
136+ // sched_yield ( ); // v 6.2.0 : not still usefull
137+ cout << " Joining tasks ..." << endl;
138+ for (i = 0 ; i < max; i++)
139+ {
140+ tasks [i]->join ( );
141+ }
142+ cout << " Joinable writing tasks without mutex completed." << endl;
143+ cout << " Deleting tasks ..." << endl;
144+ for (i = 0 ; i < max; i++)
145+ delete tasks [i];
146+ cout << endl << endl;
147+
148+ tasks.clear ( );
149+ ProtectedWriter pwriter (stdout);
150+ cout << " Creation of " << (unsigned long )max << " joinable writing tasks with mutexes ..." << endl;
151+ for (i = 0 ; i < max; i++)
152+ tasks.push_back (new WriterThread (max, pwriter));
153+ cout << " Running tasks ..." << endl;
154+ for (i = 0 ; i < max; i++)
155+ tasks [i]->startTask ( );
156+ // sched_yield ( ); // v 6.2.0 : not still usefull
157+ cout << " Joining tasks ..." << endl;
158+ for (i = 0 ; i < max; i++)
159+ {
160+ tasks [i]->join ( );
161+ // delete tasks [i];
162+ cout << " Deleting tasks." << endl;
163+ }
164+ for (i = 0 ; i < max; i++)
165+ delete tasks [i];
166+ cout << " Joinable writing tasks with mutexes completed." << endl;
167+
172168 }
173169 catch (const Exception& exc)
174170 {
175171 cout << " Exception caught : " << exc.getFullMessage ( ) << endl;
176- return -1 ;
177172 }
178173 catch (...)
179174 {
180175 cout << " Unexpected error caught." << endl;
181- return -1 ;
182176 }
183177
184178 return 0 ;
0 commit comments