PDA

View Full Version : سوال: توقف قسمتی از برنامه



هم دانشگاهی
شنبه 29 آبان 1389, 12:38 عصر
سلام دوستان!

چه طوری میتونیم قسمتی از برنامه متوقف بشه ولی بقیه برنامه به کار خودش ادامه بدهد؟

منظورم اینه که مثلا میخواهیم دو ردیف ستاره چاپ کنیم ولی یکی تند تر بره و دیگری کندتر؟

ممنون میشم اگه کمکم کنین!

glassysmart
شنبه 29 آبان 1389, 14:38 عصر
با استفاده از thread

هم دانشگاهی
شنبه 29 آبان 1389, 20:06 عصر
خب بیشتر توضیح بدین ! در مورد thread چیزی نمیدونم!

rezaricky
شنبه 29 آبان 1389, 21:51 عصر
اگه از turbo c استفاده می کنید نمیتونید این کارو بکنید چون از thread پشتیبانی نمیکنه!
بجای turbo c میتونید از C++‎ builder استفاده کنید

هم دانشگاهی
شنبه 29 آبان 1389, 22:31 عصر
من از Dev استفاده میکنم ولی منظورم این هستش که thread چیه؟

می خواستم بدونم کتابخانه دارد؟ و کلا چگونه از thread استفاده میشود؟
کسی اگه میدونه کمکم کنه! ممنون میشم!

r00tkit
یک شنبه 30 آبان 1389, 11:57 صبح
اینو بخون بفهمی thread چیست (http://en.wikipedia.org/wiki/Thread_%28computer_science%29)

بعد از این به عنوان مثال و توضیح استفاده کن (http://www.codersource.net/win32/win32-threads/multithreading-in-win32.aspx)

و
این (http://www.codeproject.com/KB/threads/Threads_1.aspx) بعد این (http://msdn.microsoft.com/en-us/library/ms682516%28VS.85%29.aspx)

اینم یه مثال:

#include <windows.h>

//Header declarations
long WINAPI ThreadTwo(long lParam);
long WINAPI ThreadThree(long lParam);
long WINAPI ThreadFour(long lParam);

int main(void)
{
HANDLE hThread[3];
DWORD dwID[3];
DWORD dwRetVal = 0;

//before multithreading, do something to show the messagebox will
//stop processing in the current thread
MessageBox(NULL,"This messagebox will stop processing of the thread. No other \nmessageboxes will appear.","Main Messagebox", NULL);

//release the threads. Remember, ThreadOne is our main thread
hThread[0] = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)Thread Two,NULL,0,&dwID[0]);
hThread[1] = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)Thread Three,NULL,0,&dwID[1]);
hThread[2] = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)Thread Four,NULL,0,&dwID[2]);

//Run the main thread as well
MessageBox(NULL,"This Messagebox is from Thread 1.","Messagebox", NULL);


//wait for all threads to complete before continuing
dwRetVal = WaitForMultipleObjects(3, hThread, TRUE, INFINITE);

//Display a messagebox to show that the Wait state has finished
MessageBox(NULL,"This Messagebox is to show that all threads have completed.","Messagebox", NULL);

//close handles
CloseHandle(hThread[0]);
CloseHandle(hThread[1]);
CloseHandle(hThread[2]);

//end the main function
return 0;
}

long WINAPI ThreadTwo(long lParam)
{
MessageBox(NULL,"This Messagebox is from Thread 2.","Messagebox", NULL);
return 0;
}

long WINAPI ThreadThree(long lParam)
{
MessageBox(NULL,"This Messagebox is from Thread 3.","Messagebox", NULL);
return 0;
}

long WINAPI ThreadFour(long lParam)
{
MessageBox(NULL,"This Messagebox is from Thread 4.","Messagebox", NULL);
return 0;
}