Click here to Skip to main content
16,006,013 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionWhat wrong with this Code ?? ( multiThread in win32 ) Pin
Yanshof23-Sep-06 5:11
Yanshof23-Sep-06 5:11 
AnswerRe: What wrong with this Code ?? ( multiThread in win32 ) Pin
Mohammad A Gdeisat23-Sep-06 6:04
Mohammad A Gdeisat23-Sep-06 6:04 
GeneralRe: What wrong with this Code ?? ( multiThread in win32 ) Pin
Yanshof23-Sep-06 6:08
Yanshof23-Sep-06 6:08 
AnswerRe: What wrong with this Code ?? ( multiThread in win32 ) Pin
Yanshof23-Sep-06 8:16
Yanshof23-Sep-06 8:16 
AnswerRe: What wrong with this Code ?? ( multiThread in win32 ) Pin
Hamid_RT23-Sep-06 8:33
Hamid_RT23-Sep-06 8:33 
AnswerRe: What wrong with this Code ?? ( multiThread in win32 ) Pin
Eytukan23-Sep-06 8:40
Eytukan23-Sep-06 8:40 
GeneralRe: What wrong with this Code ?? ( multiThread in win32 ) Pin
Yanshof23-Sep-06 8:58
Yanshof23-Sep-06 8:58 
AnswerRe: What wrong with this Code ?? ( multiThread in win32 ) Pin
Eytukan23-Sep-06 9:35
Eytukan23-Sep-06 9:35 
Oops didn't read the program fully.CS should be initialized once. Try this.
<br />
#include <conio.h><br />
<br />
using namespace std;<br />
<br />
CRITICAL_SECTION sc;<br />
<br />
void __stdcall func(LPVOID param)<br />
{<br />
	AfxMessageBox("in thread");<br />
	char szBuffer[256];<br />
	long lVal = (*(long*)param);<br />
	EnterCriticalSection(&sc);<br />
<br />
	CString cs;<br />
	cs.Format("%d",lVal);<br />
	AfxMessageBox(cs);<br />
	<br />
	int testVal=lVal;<br />
	while(lVal > 0)<br />
	{<br />
	sprintf(szBuffer, "I'm %d lVal is : %ld \n",testVal,lVal--);<br />
	printf(szBuffer);<br />
	}<br />
	<br />
	LeaveCriticalSection(&sc);<br />
AfxMessageBox("done");	<br />
}<br />
<br />
<br />
void main(void)<br />
{<br />
HANDLE thread1,thread2;<br />
<br />
long lVal = 5000;// changed to test<br />
	InitializeCriticalSection(&sc);<br />
thread1 = CreateThread(NULL,5,(LPTHREAD_START_ROUTINE)func,&lVal,CREATE_SUSPENDED,NULL);<br />
<br />
<br />
SetThreadPriority(thread1, THREAD_PRIORITY_HIGHEST);<br />
<br />
long lVal2 = 1000; // changed to test<br />
<br />
thread2 = CreateThread(NULL,5,(LPTHREAD_START_ROUTINE)func,&lVal2,CREATE_SUSPENDED,NULL);<br />
<br />
SetThreadPriority(thread2, THREAD_PRIORITY_HIGHEST);<br />
<br />
ResumeThread(thread1); Sleep(3000); // changed to test<br />
ResumeThread(thread2);<br />
<br />
WaitForSingleObject(thread2, 500); // changed to test<br />
WaitForSingleObject(thread1, 500); // changed to test<br />
while(getch()!=27); // changed to test<br />
}<br />

Just did this one for test. Try it and tell me if it's useful or not. It's too late here .. see u tomorrow.. goodnight Wink | ;)






<marquee scrollamount="1" scrolldelay="1" direction="up" height="10" step="1">--[Jig | [Dance] ]--

[My Current Status]

Link2006 wrote:Let's take it outside of CP
Jeremy : Please don't.I would love to see this.I'm making the popcorn already.

QuestionHow to Unload CListCtrl Pin
georgekjolly23-Sep-06 4:12
georgekjolly23-Sep-06 4:12 
AnswerRe: How to Unload CListCtrl Pin
ThatsAlok23-Sep-06 6:02
ThatsAlok23-Sep-06 6:02 
AnswerRe: How to Unload CListCtrl Pin
Jörgen Sigvardsson23-Sep-06 8:20
Jörgen Sigvardsson23-Sep-06 8:20 
GeneralRe: How to Unload CListCtrl Pin
ThatsAlok23-Sep-06 9:09
ThatsAlok23-Sep-06 9:09 
GeneralRe: How to Unload CListCtrl Pin
Jörgen Sigvardsson23-Sep-06 9:11
Jörgen Sigvardsson23-Sep-06 9:11 
GeneralRe: How to Unload CListCtrl Pin
ThatsAlok4-Oct-06 7:35
ThatsAlok4-Oct-06 7:35 
GeneralRe: How to Unload CListCtrl Pin
Jörgen Sigvardsson4-Oct-06 8:17
Jörgen Sigvardsson4-Oct-06 8:17 
GeneralRe: How to Unload CListCtrl Pin
ThatsAlok4-Oct-06 9:19
ThatsAlok4-Oct-06 9:19 
AnswerRe: How to Unload CListCtrl Pin
Hamid_RT23-Sep-06 8:25
Hamid_RT23-Sep-06 8:25 
AnswerRe: How to Unload CListCtrl Pin
Eytukan23-Sep-06 8:53
Eytukan23-Sep-06 8:53 
QuestionRe: How to Unload CListCtrl Pin
Bravoone_200625-Sep-06 1:59
Bravoone_200625-Sep-06 1:59 
AnswerRe: How to Unload CListCtrl Pin
Eytukan25-Sep-06 2:06
Eytukan25-Sep-06 2:06 
QuestionWebBrowser Control – to detect type of loaded document Pin
KellyLynch23-Sep-06 2:52
KellyLynch23-Sep-06 2:52 
QuestionCollaboration Data Objects (1.x) Pin
neha.agarwal2723-Sep-06 2:38
neha.agarwal2723-Sep-06 2:38 
AnswerRe: Collaboration Data Objects (1.x) Pin
JWood23-Sep-06 4:14
JWood23-Sep-06 4:14 
GeneralRe: Collaboration Data Objects (1.x) Pin
ThatsAlok23-Sep-06 6:06
ThatsAlok23-Sep-06 6:06 
GeneralRe: Collaboration Data Objects (1.x) Pin
Hamid_RT23-Sep-06 8:43
Hamid_RT23-Sep-06 8:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.