[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
problems with simple examples...
From: |
vitormr |
Subject: |
problems with simple examples... |
Date: |
Mon, 13 Oct 2003 15:41:31 -0300 |
User-agent: |
Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax) |
Hello,
I have some problems to generate a Makefile for my examples. Can you
help me?
I need a Makefile example to compile a generic .cpp example as a
documentation
examples (e.g., bug1, bug2...).
In attach you can see my Makefiles and a simple example.
Thank you,
VĂtor
#include <cc++2/cc++/thread.h>
#include <cstdio>
#ifdef CCXX_NAMESPACES
using namespace std;
using namespace ost;
#endif
// This is a little regression test
//
class ThreadTest: public Thread
{
public:
ThreadTest();
void run();
};
volatile int n = 0;
bool WaitNValue(int value)
{
for(int i=0;; ++i)
{
if (n == value)
break;
if (i >= 100)
return false;
Thread::sleep(10);
}
return true;
}
bool WaitChangeNValue(int value)
{
for(int i=0;; ++i)
{
if (n != value)
break;
if (i >= 100)
return false;
Thread::sleep(10);
}
return true;
}
ThreadTest::ThreadTest()
{
}
void ThreadTest::run()
{
setCancel(Thread::cancelDeferred);
n = 1;
// wait for main thread
if (!WaitNValue(2)) return;
// increment infinitely
for(;;)
{
yield();
n = n+1;
}
}
bool TestChange(bool shouldChange)
{
if (shouldChange)
printf("- thread should change n...");
else
printf("- thread should not change n...");
if (WaitChangeNValue(n) == shouldChange)
{
printf("ok\n");
return true;
}
printf("ko\n");
return false;
}
#undef ERROR
#undef OK
#define ERROR {printf("ko\n"); return 1; }
#define OK {printf("ok\n"); }
#define TEST_CHANGE(b) if (!TestChange(b)) return 1;
int main(int argc, char* argv[])
{
ThreadTest test;
// test only thread, without sincronization
printf("***********************************************\n");
printf("* Testing class Thread without syncronization *\n");
printf("***********************************************\n");
printf("Testing thread creation\n\n");
n = 0;
test.start();
// wait for n == 1
printf("- thread should set n to 1...");
if (WaitNValue(1)) OK
else ERROR;
// increment number in thread
printf("\nTesting thread is working\n\n");
n = 2;
TEST_CHANGE(true);
TEST_CHANGE(true);
// suspend thread, variable should not change
printf("\nTesting suspend & resume\n\n");
test.suspend();
TEST_CHANGE(false);
TEST_CHANGE(false);
// resume, variable should change
test.resume();
TEST_CHANGE(true);
TEST_CHANGE(true);
printf("\nTesting recursive suspend & resume\n\n");
test.suspend();
test.suspend();
TEST_CHANGE(false);
TEST_CHANGE(false);
test.resume();
TEST_CHANGE(false);
TEST_CHANGE(false);
test.resume();
TEST_CHANGE(true);
TEST_CHANGE(true);
printf("\nTesting no suspend on resume\n\n");
test.resume();
TEST_CHANGE(true);
TEST_CHANGE(true);
// suspend thread, variable should not change
printf("\nTesting resuspend\n\n");
test.suspend();
TEST_CHANGE(false);
TEST_CHANGE(false);
printf("\nNow program should finish... :)\n");
test.resume();
return 0;
}
INCDIR = -I. -I$(HOME)/library/include/cc++2 -I$(HOME)/library/include
-D_GNU_SOURCE
LIBDIR = -L. -L$(HOME)/library/lib
LIBS = -lccext2 -lccgnu2 -lxml2 -lz -ldl -lpthread $(EXTRA_LIBS)
EXE = $(MODULE).x
.SUFFIXES: .cc .cpp .o .x
$(EXE): $(OBJS) $(HOME)/library/lib/libccgnu2.a $(HOME)/library/lib/libccext2.a
$(CC) $(CFLAGS) $(INCDIR) $(LIBDIR) -o $@ $(OBJS) $(LIBS) 2>&1 | c++filt
.cpp.o:
$(CC) $(CFLAGS) $(INCDIR) -c $<
.cc.o:
$(CC) $(CFLAGS) $(INCDIR) -c $<
clean::
rm -f $(OBJS) *~ $(EXE) core
CC = g++
OPT = -O3
DEBUG = -g
OTHER = -Wall -lpthread
CFLAGS = $(OPT) $(OTHER)
#CFLAGS = $(DEBUG) $(OTHER)
MODULE = run
include Makefile.srcs
OBJS = $(SRCS:.cpp=.o)
include ./Makefile.defs
SRCS = \
bug1.cpp
- problems with simple examples...,
vitormr <=