Monday, March 24, 2008

pthread vs Boost::Thread

May this code snippet is useful.

In pthread:

#include "pthread.h"
class Reader { // Class to spawn ReadThread
public:
void ReadBuffer();
private:
void ReadThread();
static void *_ReadThread(void*);
};
void Reader::ReadBuffer() {
pthread_t thread;
pthread_create(&thread, NULL, _ReadThread, (void *) this);
}
void *Reader::_ReadThread(void *ptr) {
Reader *that=(Reader )ptr;
that->ReadThread();
return(0);
};
void Reader::ReadThread() {//your thread function
}

In Boost::Thread:

#include "boost/thread/thread.hpp"
#include "boost/bind.hpp"

class Reader { // Class to spawn ReadThread
public:
void ReadBuffer();
private:
void ReadThread(int id); // boost thread
};
void Reader::ReadBuffer() {
int threadID;

boost::thread readThrd(boost::bind(&Reader::ReadThread, this, threadID);
}
void Reader::ReadThread() {//your thread function
}

Boost::Thread is also crossplatform and very neatly OO-programmed.
Why multithread ?

Sunday, March 23, 2008

Darkness inside Killeroo

Killeroo sees the light

MSVC Backward Compatibility

Some links concerning MSVC's backward compatibility issues.

1. VC++ 6.0, 7.0, and 8.0 Compatibility
2.
Breaking Changes in the Visual C++ Compiler.
3. MSVC Languange and Compiler Issues.
4. VC++ 7 to VC++ 6 Project Converter 1.0.

Let's face the spaghetti world, since C++ is built on top of C.
A programmer is a Polymath (or Polythink).

There are only two kinds of languages: the ones people complain about and the ones nobody uses. (Bjarne Stroustrup)

Saturday, March 22, 2008

PBRT without MSVC

PBRT is awesome. But the problem is the source code was supposed to be build using MSVC. It seems after searching the PBRT forum and googling, currently nobody has ever tried to build the code without MSVC on Windows (on Linux is said to be fine, but we have to modify the core source). I spent about several hours yesterday to build it using Code::Blocks and Mingw. It runs quite smooth until when I have to link Openexr prebuild for MSVC. Some issues around MSVC and Mingw like functions and DLL calls compatibility. Especially, the DLL link issue is still difficult to handle using currently available dlltool, reimp, and pexports. The only thinkable solutions at present are: (1) Build the Openexr source using Mingw, (2) Eplicitly call MSVC DLL using LoadLibrary() and getProcessAddress()... But currently, I don't have time, maybe later. Facing these problems, now I remember why while we are in Java we insist on pure Java, and focus on solving the problem rather than the tools. But let us face this reality and gain some lessons and understanding. Maybe later we will make PBRT in Java. Here I take a note on some relevant links.

http://www.mingw.org/MinGWiki/index.php/MixingCompilers

http://aegisknight.org/cppinterface.html

http://www.codeguru.com/forum/archive/index.php/t-379193.html

Here is other important tip to compile PBRT on MSVC.