#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    3
    Rep Power
    0

    Creating a thread


    Hi,

    I wrote the following code:

    Code:
    #include <stdio.h>
    #include <Windows.h>
    
    
    void ThreadFunction (int* index)
    {
    	(*index) = (*index)+1;
    
    }
    
    
    void main()
    {
    	
    	int index=0;
    	HANDLE ReadPicThread;
    
    	ReadPicThread=CreateThread( NULL, 0 /*use default stack size*/, (LPTHREAD_START_ROUTINE) ThreadFunction /* thread function*/,
    	&index /* argument to thread function */,0 ,NULL	/* returns the thread identifier */  );
    	
    	printf("%d", index);
    
    	CloseHandle(ReadPicThread);
    }
    Unfortunately, This code pass compilation, but it doesn't print anything on the screen. I was trying to put a breakpint, and once I operate the debug mode (F5), the program breaks down.

    What is the problem ?
    Last edited by MatanBarLev; January 5th, 2013 at 01:30 PM. Reason: Rephrase
  2. #2
  3. Lord of the Dance
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2003
    Posts
    3,644
    Rep Power
    1945
    If you get any error messages you should post them.
    On which line exactly does it break down?

    You should also control if CreateThread succeeded the call by checking the value in ReadPicThread for a NULL value.

IMN logo majestic logo threadwatch logo seochat tools logo