Results 1 to 7 of 7

Thread: Problem in compiling Threadpool functions like QueUserWorkItem()

  1. #1
    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?

  2. #2
    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.

  3. #3
    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);

  4. #4
    Join Date
    Oct 2005
    Posts
    2,394

    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.

  5. #5
    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?

  6. #6
    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.

  7. #7
    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.

Similar Threads

  1. Any instruction on compiling WPS v2.2
    By Ravana in forum Software Development
    Replies: 6
    Last Post: 29-09-2010, 11:58 PM
  2. Problem with router's UPNP functions
    By Acalapati in forum Networking & Security
    Replies: 5
    Last Post: 28-03-2010, 02:32 AM
  3. Problem compiling Wine 1.1.36 on Mac OS X
    By L-cynthiya in forum Operating Systems
    Replies: 5
    Last Post: 12-01-2010, 06:42 PM
  4. Problem compiling with Generic
    By Macadrian in forum Software Development
    Replies: 4
    Last Post: 12-12-2009, 05:38 PM
  5. Problem compiling OpenGL
    By Hakon in forum Software Development
    Replies: 3
    Last Post: 28-04-2009, 01:51 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •