Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



Problem in compiling Threadpool functions like QueUserWorkItem()

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 22-09-2010
Member
 
Join Date: Apr 2010
Posts: 32
Problem in compiling Threadpool functions like QueUserWorkItem()
  

I would like to increase the number of threads on my video coded application with the help of threadpool functions. Here is what I have done until now. The problem is that I am unable to compile it.
Code:
#include<windows.h>
#include<stdio.h>
#include<conio.h>
#define THREAD_SIZE 6
DWORD WINAPI lprint(LPVOID p);
struct node
{
int p,q;
};
typedef struct node* NODEPTR;
void main()
{
NODEPTR ptr[THREAD_SIZE];
DWORD th[THREAD_SIZE];
BOOL hth[THREAD_SIZE];
int i;
for(i=0;i<THREAD_SIZE;i++)
{
ptr[i]=(NODEPTR)malloc(sizeof(NODEPTR));
ptr[i]->p=i;
ptr[i]->q=i*1000;
//hth[i]=CreateThread(NULL,0,lprint,ptr[i],0,&th[i]);
hth[i]=QueueUserWorkItem(lprint,ptr[i],WT_EXECUTEDEFAULT);
//WT_EXECUTEINIOTHREAD
}
WaitForMultipleObjects(THREAD_SIZE, hth , TRUE, INFINITE);
for(i=0;i<THREAD_SIZE;i++)
{
CloseHandle(hth[i]);
}
getch();
}
DWORD WINAPI lprint(LPVOID l)
{
NODEPTR s1=(NODEPTR) l;
printf("%d %d\n",s1->p,s1->q);
return 0;
}
It gives me an error message which states "error C3861: 'QueueUserWorkItem': identifier not found. Is there someone who can explain me this and provide a solution to it?

Reply With Quote
  #2  
Old 22-09-2010
Member
 
Join Date: Nov 2008
Posts: 1,022
Re: Problem in compiling Threadpool functions like QueUserWorkItem()

A compiler reads the code from top to bottom. It first looks for the header files and then imports all the classes and functions that are included in it and then directly goes into your main(). According to your code, 'QueueUserWorkItem' is undefined. Do you have its definition included in your windows.h file? If it isn't then you have to define it explicitly before it is being used.
Reply With Quote
  #3  
Old 22-09-2010
Member
 
Join Date: Nov 2008
Posts: 996
Re: Problem in compiling Threadpool functions like QueUserWorkItem()

I think you are having an old SDK and so QueUserWorkItem() is left unidentified. The windows.h file doesn't have its definition. You need to install the latest one and thus your file will be changed to winbase.h. If you don't want to install the new SDK then simply insert the below statement on the first line of your main():

Code:
QueueUserWorkItem(func, 0, 0);
Reply With Quote
  #4  
Old 22-09-2010
Member
 
Join Date: Oct 2005
Posts: 2,389
Re: Problem in compiling Threadpool functions like QueUserWorkItem()

The fact that you are trying to do is calling a function which is undefined or undeclared. Check your header files and see if it exists somewhere or not. If it isn't then declare it in your code and then try to compile the code.
Reply With Quote
  #5  
Old 23-09-2010
Member
 
Join Date: Apr 2010
Posts: 32
Re: Problem in compiling Threadpool functions like QueUserWorkItem()

Ok thanks for your input. My windows.h file had its definition but the only thing was that it declaration was commented (//) and that was what creating a problem for me. I removed those comments sign and now my code is working. Anyways thanks everyone. One more question that I would like to ask is that I have read somewhere few days about WT_EXECUTELONGFUNCTION flag of QueueUserWorkItem function. But I didn't understood much about its concept. Can you all help me understanding what it is exactly and what is the advantage of using it?
Reply With Quote
  #6  
Old 24-09-2010
Member
 
Join Date: Nov 2008
Posts: 996
Re: Problem in compiling Threadpool functions like QueUserWorkItem()

First let get to the basic concept like why we use QueueUserWorkItem function. It is used to delay a work item to execute. But now the point comes like for how long it should wait, whether it should create a new thread or not and how to manage this. Here comes into the picture the WT_EXECUTELONGFUNCTION flag. This flag helps the thread pool to decide whether to add a new thread to the pool; it forces the thread pool to create a new thread if all of the threads in the pool are busy. So if you have 10,000 work items in the queue at the same time, 10,000 threads will be added to the thread pool. If you do not want 10,000 threads to be created, then you must space out the calls to QueueUserWorkItem so that some work items get a chance to complete.
Reply With Quote
  #7  
Old 25-09-2010
Member
 
Join Date: Nov 2008
Posts: 1,022
Re: Problem in compiling Threadpool functions like QueUserWorkItem()

WT_EXECUTELONGFUNCTION (0x00000010) is the callback function to perform a long wait. This flag helps the system to decide if it should create a new thread. In other words, the thread pool uses this flag to decide whether it should create a new thread or wait for an existing one to finish. If you use WT_EXECUTELONGFUNCTION flag then the system will be very resistive to create a new thread, and this is the main reason that you will have more threads than CPU's.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Problem in compiling Threadpool functions like QueUserWorkItem()"
Thread Thread Starter Forum Replies Last Post
Any instruction on compiling WPS v2.2 Ravana Software Development 6 30-09-2010 12:58 AM
Problem with router's UPNP functions Acalapati Networking & Security 5 28-03-2010 03:32 AM
Problem compiling Wine 1.1.36 on Mac OS X L-cynthiya Operating Systems 5 12-01-2010 07:42 PM
Problem compiling with Generic Macadrian Software Development 4 12-12-2009 06:38 PM
Problem compiling OpenGL Hakon Software Development 3 28-04-2009 02:51 PM


All times are GMT +5.5. The time now is 10:05 PM.