C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 5th, 2013, 12:47 PM
MatanBarLev MatanBarLev is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 3 MatanBarLev User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 m 59 sec
Reputation 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

Reply With Quote
  #2  
Old January 5th, 2013, 03:16 PM
MrFujin's Avatar
MrFujin MrFujin is offline
Lord of the Dance
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Oct 2003
Posts: 3,129 MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 2 Weeks 22 h 45 m 33 sec
Reputation Power: 1736
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Creating a thread

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap