deadlock and some other fixes
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
/* testChannelSearcManager.cpp */
|
||||
|
||||
#include <channelSearchManager.h>
|
||||
#include <sstream>
|
||||
|
||||
using namespace epics::pvData;
|
||||
using namespace epics::pvAccess;
|
||||
@@ -17,22 +18,94 @@ private:
|
||||
string _channelName;
|
||||
};
|
||||
|
||||
static const int max_channels = 100;
|
||||
ClientContextImpl* context = new ClientContextImpl();
|
||||
ChannelSearchManager* manager = new ChannelSearchManager(context);
|
||||
TestSearcInstance** chanArray = new TestSearcInstance*[max_channels];
|
||||
|
||||
void* testWorker1(void* p)
|
||||
{
|
||||
for(int i = 0; i < 1000; i++)
|
||||
{
|
||||
for(int j = 0; j < max_channels/2; j++)
|
||||
{
|
||||
manager->unregisterChannel(chanArray[j]);
|
||||
usleep(100);
|
||||
manager->registerChannel(chanArray[j]);
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
void* testWorker2(void* p)
|
||||
{
|
||||
for(int i = 0; i < 1000; i++)
|
||||
{
|
||||
for(int j = max_channels/2; j < max_channels; j++)
|
||||
{
|
||||
manager->unregisterChannel(chanArray[j]);
|
||||
usleep(100);
|
||||
manager->registerChannel(chanArray[j]);
|
||||
manager->beaconAnomalyNotify();
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int main(int argc,char *argv[])
|
||||
{
|
||||
ClientContextImpl* context = new ClientContextImpl();
|
||||
ChannelSearchManager* manager = new ChannelSearchManager(context);
|
||||
pthread_t _worker1Id;
|
||||
pthread_t _worker2Id;
|
||||
|
||||
TestSearcInstance* chan1 = new TestSearcInstance("chan1", 1);
|
||||
manager->registerChannel(chan1);
|
||||
ostringstream obuffer;
|
||||
for(int i = 0; i < max_channels; i++)
|
||||
{
|
||||
obuffer.clear();
|
||||
obuffer.str("");
|
||||
obuffer << i;
|
||||
string name = "chan" + obuffer.str();
|
||||
chanArray[i] = new TestSearcInstance(name.c_str(), i);
|
||||
manager->registerChannel(chanArray[i]);
|
||||
}
|
||||
|
||||
sleep(3);
|
||||
//create two threads
|
||||
int32 retval = pthread_create(&_worker1Id, NULL, testWorker1, NULL);
|
||||
if(retval != 0)
|
||||
{
|
||||
assert(true);
|
||||
}
|
||||
|
||||
retval = pthread_create(&_worker2Id, NULL, testWorker2, NULL);
|
||||
if(retval != 0)
|
||||
{
|
||||
assert(true);
|
||||
}
|
||||
|
||||
retval = pthread_join(_worker1Id, NULL);
|
||||
if(retval != 0)
|
||||
{
|
||||
assert(true);
|
||||
}
|
||||
|
||||
retval = pthread_join(_worker2Id, NULL);
|
||||
if(retval != 0)
|
||||
{
|
||||
assert(true);
|
||||
}
|
||||
|
||||
manager->cancel();
|
||||
|
||||
context->destroy();
|
||||
getShowConstructDestruct()->constuctDestructTotals(stdout);
|
||||
|
||||
//if(chan1) delete chan1;
|
||||
for(int i = 0; i < max_channels; i++)
|
||||
{
|
||||
if(chanArray[i]) delete chanArray[i];
|
||||
}
|
||||
if(chanArray) delete [] chanArray;
|
||||
if(manager) delete manager;
|
||||
if(context) delete context;
|
||||
return(0);
|
||||
|
||||
Reference in New Issue
Block a user