//the naive query processor, just pick the query random one by one.
DWORD WINAPI tp_naiveQP( LPVOID lpParam ) 
{ 
	tp_batchQuery* pData;
	pData = (tp_batchQuery*)lpParam;
	int totalQuery=pData->totalQuery;
	char** sqlQuery=pData->sqlQuery;
	Query_stat *gQstat=pData->stat;
	int threadid=pData->threadid;
	int curQuery;
	char* query=NULL;
	setHighPriority();
	while(1)
	{
		//get the tuples to sort
		EnterCriticalSection(&(PoolLock));
		curQuery=CurentID++;
		LeaveCriticalSection(&(PoolLock));
		if(curQuery>=numQueries) 
		{
			break;
		}
		query=sqlQuery[curQuery];//the query pick going to be execute

		tp_singleQuery* pData = (tp_singleQuery*) HeapAlloc(GetProcessHeap(),
				HEAP_ZERO_MEMORY, sizeof(tp_singleQuery));
		pData->init(gQstat[curQuery].eM,query,curQuery,threadid);
		tp_QueryThread(pData);
		HeapFree(GetProcessHeap(),0, pData);
		//resetGPU();
	}
	return 0;
} 
void tp_QueryThread(tp_singleQuery* _pData)
{
	char* query=_pData->query;
	EXEC_MODE eM=_pData->eM;
	int id=_pData->id;
	int tid=_pData->postThreadID;
	setHighPriority();
	QueryPlanTree tree;//set GPUONLY_QP always false. Assume CoProcessor can only see host data. so directly cancell it.
	tree.buildTree(query);
	tree.execute(eM);
	int len=tree.planStatus->numResultColumn*tree.planStatus->numResultRow;
	free(tree.planStatus->finalResult);
}
static void *waitForData0(void *arg)
{
	(void)arg;

	setHighPriority(10);
	while(1)
	{
	    if (waitForInterrupt (D0_PIN, -1) > 0)
	    {
			bitCount++;
			flagDone = 0;
			wiegand_counter = WIEGAND_WAIT_TIME;  
	    }
	}

	return NULL;
}