Simple data sharing between theads

Multi-threading allows you to execute portions of your code concurrently. While on a single CPU the benefits of multi-threading are limited, multi-core systems allow true concurent execution, thus reducing the time it takes for the task to finish.

The basic threading is easy, you just declare a function and run it in thread.

#include <thread>
#include <iostream>
using namespace std;

void complicatedCalculation1()
{//Do stuff here}

void complicatedCalculation2()
{//Do stuff here}

int main()
   //Creates a thread and starts it
   thread calc1Thread(complicatedCalculation1);

   //Creates a thread and starts it
   thread calc2Thread(complicatedCalculation1);

   //Wait for each thread to finish

   cout<<"All done"<<endl;
   return 0;

Continue reading “Simple data sharing between theads”

Google’s gtest not handling friend tests correctly

I was using Google’s gtest unit test framework today and I found an annoying problem – you can’t properly friend test methods that are in a different namespace than the class being tested.

Here is a typical situation:

namespace MyNamespace
   class MyClass
         MyClass(int inData): data(inData){}
         int data;
}//end namespace

namespace MyNamespace
namespace TEST
   class MyTestClassFixture
      static const int fixtureData;
   static const MyTestClassFixture::fixtureData = 5;

   TEST_F(MyTestClassFixture, TestEqual)
      MyClass testClass(5);

Continue reading “Google’s gtest not handling friend tests correctly”

Oracle C++ API non-sense

I spent 2 hours trying to figure out this nonsense. Here is the problem:

Environment *env = Environment::createEnvironment();
Connection *conn = env->createConnection("username", "password",
string sqlQueryText = "UPDATE myTable SET field4 =:p4, field3 =:p3
WHERE field2 :=p2 AND field1 :=p1";
Statement* updateStatement = conn->createStatement(sqlQueryText);

updateStatement.setInt(1, field1Var);
updateStatement.setString(2, field2Var);
updateStatement.setInt(3, field3Var);
updateStatement.setString(4, field4Var);


Continue reading “Oracle C++ API non-sense”