| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | threads, threads, more threads |
I have a question about using more than two threads in a PM application. I
create an object window which handles messages sent to threads (different
parts of my program want to do things simultaneously, e.g. read one file
and display other). I use the /same/ thread function for all threads.
Is this OK to do? Are there any situations in which my program would behave
erroneusly?
THREADPARMS *pThread1;
THREADPARMS *pThread2;
int main (int argc, char **argv)
{
.
.
pThread1 = (THREADPARMS *) malloc (sizeof (THREADPARMS));
pThread2 = (THREADPARMS *) malloc (sizeof (THREADPARMS));
.
.
// create window etc.
.
.
}
MRESULT EXPENTRY MainWndProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
{
switch (msg)
{
case WM_CREATE:
.
.
pThread1->tidObject = _beginthread (workerThread, NULL, STACKSIZE,
(PVOID) pThread1);
pThread2->tidObject = _beginthread (workerThread, NULL, STACKSIZE,
(PVOID) pThread2);
.
.
case WM_COMMAND:
// send messages to threads here
.
.
case WM_CLOSE:
WinPostMsg (pThread1->hwndObject, WM_QUIT, 0, 0);
WinPostMsg (pThread2->hwndObject, WM_QUIT, 0, 0);
return FALSE;
case WM_DESTROY:
.
.
DosWaitThread (&pThread1->tidObject, DCWW_WAIT);
DosWaitThread (&pThread2->tidObject, DCWW_WAIT);
}
...
}
MRESULT EXPENTRY ObjectWinProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
{
switch (msg)
{
case UM_START_SEARCH: // fill listbox
.
.
case UM_REDISPLAY: // redisp listbox with changed options
.
.
case UM_IMPORT_MLE: // read file into MLE
.
.
etc.
}
void workerThread (void *arg)
{
THREADPARMS *pThread;
HAB habLB;
HMQ hmqLB;
QMSG qmsg;
pThread = (THREADPARMS *) arg;
DosSetPriority (PRTYS_THREAD, PRTYC_IDLETIME, pThread->prtyDelta, 0UL);
habLB = WinInitialize ((USHORT) 0);
hmqLB = WinCreateMsgQueue (habLB, 0);
WinCancelShutdown (hmqLB, TRUE);
WinRegisterClass (habLB, szClassObject,
(PFNWP) ObjectWinProc, 0, sizeof (THREADPARMS *));
pThread->hwndObject = WinCreateWindow (HWND_OBJECT, szClassObject, "",
0, 0, 0, 0, 0, HWND_OBJECT, HWND_BOTTOM, 0, (PVOID)pThread, NULL);
WinPostMsg (pThread->hwndClient, UM_ACK, (MPARAM) UM_THREAD_READY,
(PVOID) pThread); // send usermessage that thread is ready
while (WinGetMsg (habLB, &qmsg, 0, 0, 0))
{
WinDispatchMsg (habLB, &qmsg);
}
WinPostMsg (pThread->hwndClient, WM_QUIT, 0, 0);
WinDestroyWindow (pThread->hwndObject);
WinDestroyMsgQueue (hmqLB);
WinTerminate (habLB);
_endthread ();
}
// Albert
---
* Origin: Albert's Point/2 in Finland, Europe (2:221/360.20)SEEN-BY: 12/2442 54/54 620/243 624/50 632/348 640/820 690/660 711/409 410 413 SEEN-BY: 711/430 807 808 809 934 712/353 623 713/888 800/1 @PATH: 221/360 0 220/841 201/2104 109/347 2 1 3615/50 229/2 @PATH: 12/2442 711/409 54/54 711/808 809 934 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.