Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added new job-thread test, updated Job and config for DEBUG by default

  • Loading branch information...
commit e525995f4e9343342ca0aeecbcbefb5559a900b4 1 parent 0c87f7f
Daniel (dmilith) Dettlaff authored
View
2  config.h
@@ -12,7 +12,7 @@
#include <string>
-//#define DEBUG
+#define DEBUG
#define RUBY_LOCAL_INSTALL // if defined then we'll look for headers in /usr/local instead of /usr
// TODO: #define RUBY_EMB // if defined we'll use Ruby As Embeeded Scripting Language
View
1  job.cpp
@@ -45,7 +45,6 @@ Job::set_action( ETypeOfJob type_ ) {
void
Job::run() {
-#define DEBUG
// matter on job type, do something with data
switch ( type ) {
case action_IDLE:
View
1  job.h
@@ -19,6 +19,7 @@
#include "coordinates.h"
#include "core.h"
#include "hashlib/hl_tools.h"
+#include "config.h"
using namespace std;
using namespace core;
View
2  tests/Sconstruct
@@ -106,7 +106,7 @@ release14.Program('test_job_0' , 'jobs/job_test_0.cpp',
'world', 'purecore'],
LIBPATH=[ '.', '../', '/usr/local/lib', '/usr/lib' ])
-release15 = Environment( CXX = 'g++ -O0 -ggdb -W' )
+release15 = Environment( CXX = 'g++ -Os -W' )
release15.Program('test_job_thread_0' , 'jobs/job_thread_test.cpp',
LIBS=[ 'boost_thread', 'hl-sha', 'purecore', 'job', 'character', 'coordinates',
'item', 'map', 'place', 'soul', 'theritory',
View
33 tests/jobs/job_thread_test.cpp
@@ -4,6 +4,9 @@
#include <fstream>
#include <boost/shared_ptr.hpp>
#include <boost/thread/thread.hpp>
+#include <boost/thread/xtime.hpp>
+#include <boost/progress.hpp>
+#include <ctime>
#include "../../hashlib/hl_tools.h"
#include "../../coordinates.h"
@@ -26,10 +29,11 @@ extern void create_job( Cobject* object0, Cobject* object1 );
void
run() {
+ boost::xtime xt;
boost::mutex mutex;
Csoul *x = new Csoul();
Csoul *y = new Csoul();
-
+
x->set_mana( 56700000 );
y->set_mana( 12300000 );
Job *job = new Job();
@@ -38,20 +42,37 @@ run() {
cout << endl << job->get_actor( 0 ).get_mana() << flush << endl;
assert( (uint64_t)job->get_actor( 0 ).get_mana() == (uint64_t)56700000 );
assert( (uint64_t)job->get_actor( 1 ).get_mana() == (uint64_t)12300000 );
-
+
boost::mutex::scoped_lock lock( mutex );
job->run();
-
+
+ boost::xtime_get( &xt, boost::TIME_UTC );
+ xt.nsec += 5000; // just slow down the loop
+ boost::thread::sleep( xt );
+
+ delete x;
+ delete y;
delete job;
}
int
main( int argc, char* argv[] ) {
+ time_t start = time( NULL );
boost::thread_group threads;
- for (int i = 0; i < 1000000; ++i)
- threads.create_thread(&run);
- cout << "Running threads." << endl;
+ for ( int i = 0; i < 32000; ++i ) { /* on my machine 77824 is max, but 32760 is max after which boost_resource error
+ is raised. ( cat /proc/sys/kernel/threads-max ) */
+ threads.create_thread( &run );
+
+#ifdef DEBUG
+ cout << "created thread " << i << endl << flush;
+#endif
+
+ }
+#ifdef DEBUG
+ cout << "Done. Quitting." << endl;
+ cout << time( NULL ) - start << "seconds";
+#endif
threads.join_all();
return 0;
}
Please sign in to comment.
Something went wrong with that request. Please try again.