Please close or delete this topic.
(Because the forum software breaks the code, I cross-posted this thread to the mailing list.)
Hi.
I'm evaluating Poco for use in our projects, especially for threads handling. It seems that Poco threads/mutex'es fail a very simple test of mutex locking. The test code is below, any ideas?
Thanks.
^
#include
using namespace std;
#include
#include
#include
using namespace Poco;
static int volatile threadCounter = 0;
static int volatile tangledThreads = 0;
static int volatile numOfThreads = 0;
static int volatile bStop = false;
class TestMutex : public Mutex
{
public:
void lockedFunc()
{
lock();
threadCounter++;
if(threadCounter != 1)
{
cout << "Mutex failed!!!" << endl;
tangledThreads++;
threadCounter = 1;
}
threadCounter--;
unlock();
}
};
class Runner : public Runnable
{
TestMutex *tMutex;
public:
Runner()
{
numOfThreads++;
tMutex = new TestMutex();
}
~Runner()
{
delete tMutex;
}
void run()
{
do
{
tMutex->lockedFunc();
Thread::sleep(33);
}
while(!bStop);
numOfThreads--;
}
};
//EDIT the number of concurrent threads
#define NUM_THREADS 300
int main (int argc, char *argv[])
{
Thread tThreads[NUM_THREADS];
Runner rThreads[NUM_THREADS];
cout << "Launching " << NUM_THREADS << " threads" << endl;
for(int i=0;i
cout << NUM_THREADS << " threads are running" << endl;
cin.get();
bStop = true;
cout << "Stopping " << NUM_THREADS << " threads" << endl;
while(numOfThreads > 0)
usleep(33000);
cout << "Stopped" << endl;
if(tangledThreads > 0)
cout << tangledThreads << " tangled threads!" << endl;
return(0);
}
^





