|
 |
|
 |
02-18-2006, 02:51 PM
|
#1 (permalink)
|
|
Jedi Master
Join Date: Feb 2006
Location: Denver, CO
Posts: 15
|
Multithreaded application in Windows XP
I'm trying to get five threads to operate concurrently under windows XP. Currently the first thread activates properly, but the second crashes, and I don't know why. If you do, *please* let me know.
P.S. I know the code is inefficient - I'm just trying to prove to myself that it can be done before I build optimizing procedures.
Code:
.386
.model flat, stdcall
include kernel32.inc
include gdi32.inc
include user32.inc
include windows.inc
include igaserver.inc
includelib kernel32.lib
includelib user32.lib
includelib gdi32.lib
.data
maintname db 'Iga Server Main Terminal', 0
peopletname db 'People', 0
tgrouptname db 'Task Groups', 0
woodtname db 'Wood Cutters', 0
farmtname db 'Farmers', 0
smithtname db 'Blacksmiths', 0
hunttname db 'Hunters', 0
maincname db 'IGASERVER', 0
peoplecname db 'IGAPEOPLE', 0
tgroupcname db 'IGATGROUP', 0
woodcname db 'IGAWOOD', 0
farmcname db 'IGAFARM', 0
smithcname db 'IGASMITH', 0
huntcname db 'IGAHUNT', 0
.data?
fperson person <?>
fvillage village <?>
mainmsg MSG <?>
peoplemsg MSG <?>
tgroupmsg MSG <?>
woodmsg MSG <?>
farmmsg MSG <?>
smithmsg MSG <?>
huntmsg MSG <?>
mainwc WNDCLASS <?>
peoplewc WNDCLASS <?>
tgroupwc WNDCLASS <?>
woodwc WNDCLASS <?>
farmwc WNDCLASS <?>
smithwc WNDCLASS <?>
huntwc WNDCLASS <?>
mainhinst dd ?
peoplehinst dd ?
tgrouphinst dd ?
woodhinst dd ?
farmhinst dd ?
smithhinst dd ?
hunthinst dd ?
mainhwnd dd ?
peoplehwnd dd ?
tgrouphwnd dd ?
woodhwnd dd ?
farmhwnd dd ?
smithhwnd dd ?
hunthwnd dd ?
mainthr dd ?
peoplethr dd ?
tgroupthr dd ?
woodthr dd ?
farmthr dd ?
smiththr dd ?
huntthr dd ?
.code
start:
; Start main thread
push 0
push 1000
push offset main_thread
push 0
push 0
push dword ptr [mainthr]
call CreateThread
; Start people thread
push 0
push 1000
push offset people_thread
push 0
push 0
push dword ptr [peoplethr]
call CreateThread
; Start task group thread
push 0
push 1000
push offset tgroup_thread
push 0
push 0
push dword ptr [tgroupthr]
call CreateThread
; Start wood cutter thread
push 0
push 1000
push offset wood_thread
push 0
push 0
push dword ptr [woodthr]
call CreateThread
; Start farmer thread
push 0
push 1000
push offset farm_thread
push 0
push 0
push dword ptr [farmthr]
call CreateThread
; Start blacksmith thread
push 0
push 1000
push offset smith_thread
push 0
push 0
push dword ptr [smiththr]
call CreateThread
; Start hunter thread
push 0
push 1000
push offset hunt_thread
push 0
push 0
push dword ptr [huntthr]
call CreateThread
main_thread:
push 0
call GetModuleHandle
mov dword ptr [mainhinst], eax
main_thread_reg_class:
mov dword ptr [mainwc.style], CS_HREDRAW+CS_VREDRAW+CS_GLOBALCLASS
mov dword ptr [mainwc.lpfnWndProc], offset main_thread_wndproc
mov dword ptr [mainwc.cbClsExtra], 0
mov dword ptr [mainwc.cbWndExtra], 0
mov eax, dword ptr [mainhinst]
mov dword ptr [mainwc.hInstance], eax
push IDI_APPLICATION
push 0
call LoadIcon
mov dword ptr [mainwc.hIcon], eax
push IDC_CROSS
push 0
call LoadCursor
mov dword ptr [mainwc.hCursor], eax
mov dword ptr [mainwc.hbrBackground], COLOR_WINDOW+1
mov dword ptr [mainwc.lpszMenuName], 0
mov dword ptr [mainwc.lpszClassName], offset maincname
push offset mainwc
call RegisterClass
push 0
push dword ptr [mainhinst]
push 0
push 0
push CW_USEDEFAULT
push CW_USEDEFAULT
push CW_USEDEFAULT
push CW_USEDEFAULT
push WS_OVERLAPPEDWINDOW
push offset maintname
push offset maincname
push 0
call CreateWindowEx
mov dword ptr [mainhwnd], eax
push SW_SHOWNORMAL
push dword ptr [mainhwnd]
call ShowWindow
push dword ptr [mainhwnd]
call UpdateWindow
main_thread_msg_loop:
push 0
push 0
push 0
push offset mainmsg
call GetMessage
cmp eax, 0
jz main_thread_end_loop
push offset mainmsg
call TranslateMessage
push offset mainmsg
call DispatchMessage
jmp main_thread_msg_loop
main_thread_end_loop:
push dword ptr [mainmsg.wParam]
call ExitThread
main_thread_wndproc:
push ebp
mov ebp, esp
push ebx
push esi
push edi
cmp dword ptr [ebp+0Ch], WM_DESTROY
jz main_thread_wndproc_wmdestroy
jmp main_thread_wndproc_defwndproc
main_thread_wndproc_wmdestroy:
push 0
call PostQuitMessage
sub eax, eax
jmp main_thread_wndproc_finish
main_thread_wndproc_defwndproc:
push dword ptr [ebp+14h]
push dword ptr [ebp+10h]
push dword ptr [ebp+0Ch]
push dword ptr [ebp+08h]
call DefWindowProc
main_thread_wndproc_finish:
pop edi
pop esi
pop ebx
pop ebp
ret 16
people_thread:
push 0
call GetModuleHandle
mov dword ptr [peoplehinst], eax
people_thread_reg_class:
mov dword ptr [peoplewc.style], CS_HREDRAW+CS_VREDRAW+CS_GLOBALCLASS
mov dword ptr [peoplewc.lpfnWndProc], offset people_thread_wndproc
mov dword ptr [peoplewc.cbClsExtra], 0
mov dword ptr [peoplewc.cbWndExtra], 0
mov eax, dword ptr [peoplehinst]
mov dword ptr [peoplewc.hInstance], eax
push IDI_APPLICATION
push 0
call LoadIcon
mov dword ptr [peoplewc.hIcon], eax
push IDC_CROSS
push 0
call LoadCursor
mov dword ptr [peoplewc.hCursor], eax
mov dword ptr [peoplewc.hbrBackground], COLOR_WINDOW+1
mov dword ptr [peoplewc.lpszMenuName], 0
mov dword ptr [peoplewc.lpszClassName], offset peoplecname
push offset peoplewc
call RegisterClass
push 0
push dword ptr [peoplehinst]
push 0
push 0
push CW_USEDEFAULT
push CW_USEDEFAULT
push CW_USEDEFAULT
push CW_USEDEFAULT
push WS_OVERLAPPEDWINDOW
push offset peopletname
push offset peoplecname
push 0
call CreateWindowEx
mov dword ptr [peoplehwnd], eax
push SW_SHOWNORMAL
push dword ptr [peoplehwnd]
call ShowWindow
push dword ptr [peoplehwnd]
call UpdateWindow
people_thread_msg_loop:
push 0
push 0
push 0
push offset peoplemsg
call GetMessage
cmp eax, 0
jz people_thread_end_loop
push offset peoplemsg
call TranslateMessage
push offset peoplemsg
call DispatchMessage
jmp people_thread_msg_loop
people_thread_end_loop:
push dword ptr [peoplemsg.wParam]
call ExitThread
people_thread_wndproc:
push ebp
mov ebp, esp
push ebx
push esi
push edi
cmp dword ptr [ebp+0Ch], WM_DESTROY
jz people_thread_wndproc_wmdestroy
jmp people_thread_wndproc_defwndproc
people_thread_wndproc_wmdestroy:
push 0
call PostQuitMessage
sub eax, eax
jmp people_thread_wndproc_finish
people_thread_wndproc_defwndproc:
push dword ptr [ebp+14h]
push dword ptr [ebp+10h]
push dword ptr [ebp+0Ch]
push dword ptr [ebp+08h]
call DefWindowProc
people_thread_wndproc_finish:
pop edi
pop esi
pop ebx
pop ebp
ret 16
tgroup_thread:
push 0
call GetModuleHandle
mov dword ptr [tgrouphinst], eax
tgroup_thread_reg_class:
mov dword ptr [tgroupwc.style], CS_HREDRAW+CS_VREDRAW+CS_GLOBALCLASS
mov dword ptr [tgroupwc.lpfnWndProc], offset tgroup_thread_wndproc
mov dword ptr [tgroupwc.cbClsExtra], 0
mov dword ptr [tgroupwc.cbWndExtra], 0
mov eax, dword ptr [tgrouphinst]
mov dword ptr [tgroupwc.hInstance], eax
push IDI_APPLICATION
push 0
call LoadIcon
mov dword ptr [tgroupwc.hIcon], eax
push IDC_CROSS
push 0
call LoadCursor
mov dword ptr [tgroupwc.hCursor], eax
mov dword ptr [tgroupwc.hbrBackground], COLOR_WINDOW+1
mov dword ptr [tgroupwc.lpszMenuName], 0
mov dword ptr [tgroupwc.lpszClassName], offset tgroupcname
push offset tgroupwc
call RegisterClass
push 0
push dword ptr [tgrouphinst]
push 0
push 0
push CW_USEDEFAULT
push CW_USEDEFAULT
push CW_USEDEFAULT
push CW_USEDEFAULT
push WS_OVERLAPPEDWINDOW
push offset tgrouptname
push offset tgroupcname
push 0
call CreateWindowEx
mov dword ptr [tgrouphwnd], eax
push SW_SHOWNORMAL
push dword ptr [tgrouphwnd]
call ShowWindow
push dword ptr [tgrouphwnd]
call UpdateWindow
tgroup_thread_msg_loop:
push 0
push 0
push 0
push offset tgroupmsg
call GetMessage
cmp eax, 0
jz tgroup_thread_end_loop
push offset tgroupmsg
call TranslateMessage
push offset tgroupmsg
call DispatchMessage
jmp tgroup_thread_msg_loop
tgroup_thread_end_loop:
push dword ptr [tgroupmsg.wParam]
call ExitThread
tgroup_thread_wndproc:
push ebp
mov ebp, esp
push ebx
push esi
push edi
cmp dword ptr [ebp+0Ch], WM_DESTROY
jz tgroup_thread_wndproc_wmdestroy
jmp tgroup_thread_wndproc_defwndproc
tgroup_thread_wndproc_wmdestroy:
push 0
call PostQuitMessage
sub eax, eax
jmp tgroup_thread_wndproc_finish
tgroup_thread_wndproc_defwndproc:
push dword ptr [ebp+14h]
push dword ptr [ebp+10h]
push dword ptr [ebp+0Ch]
push dword ptr [ebp+08h]
call DefWindowProc
tgroup_thread_wndproc_finish:
pop edi
pop esi
pop ebx
pop ebp
ret 16
wood_thread:
push 0
call GetModuleHandle
mov dword ptr [woodhinst], eax
wood_thread_reg_class:
mov dword ptr [woodwc.style], CS_HREDRAW+CS_VREDRAW+CS_GLOBALCLASS
mov dword ptr [woodwc.lpfnWndProc], offset wood_thread_wndproc
mov dword ptr [woodwc.cbClsExtra], 0
mov dword ptr [woodwc.cbWndExtra], 0
mov eax, dword ptr [woodhinst]
mov dword ptr [woodwc.hInstance], eax
push IDI_APPLICATION
push 0
call LoadIcon
mov dword ptr [woodwc.hIcon], eax
push IDC_CROSS
push 0
call LoadCursor
mov dword ptr [woodwc.hCursor], eax
mov dword ptr [woodwc.hbrBackground], COLOR_WINDOW+1
mov dword ptr [woodwc.lpszMenuName], 0
mov dword ptr [woodwc.lpszClassName], offset woodcname
push offset woodwc
call RegisterClass
push 0
push dword ptr [woodhinst]
push 0
push 0
push CW_USEDEFAULT
push CW_USEDEFAULT
push CW_USEDEFAULT
push CW_USEDEFAULT
push WS_OVERLAPPEDWINDOW
push offset woodtname
push offset woodcname
push 0
call CreateWindowEx
mov dword ptr [woodhwnd], eax
push SW_SHOWNORMAL
push dword ptr [woodhwnd]
call ShowWindow
push dword ptr [woodhwnd]
call UpdateWindow
wood_thread_msg_loop:
push 0
push 0
push 0
push offset woodmsg
call GetMessage
cmp eax, 0
jz wood_thread_end_loop
push offset woodmsg
call TranslateMessage
push offset woodmsg
call DispatchMessage
jmp wood_thread_msg_loop
wood_thread_end_loop:
push dword ptr [woodmsg.wParam]
call ExitThread
wood_thread_wndproc:
push ebp
mov ebp, esp
push ebx
push esi
push edi
cmp dword ptr [ebp+0Ch], WM_DESTROY
jz wood_thread_wndproc_wmdestroy
jmp wood_thread_wndproc_defwndproc
wood_thread_wndproc_wmdestroy:
push 0
call PostQuitMessage
sub eax, eax
jmp wood_thread_wndproc_finish
wood_thread_wndproc_defwndproc:
push dword ptr [ebp+14h]
push dword ptr [ebp+10h]
push dword ptr [ebp+0Ch]
push dword ptr [ebp+08h]
call DefWindowProc
wood_thread_wndproc_finish:
pop edi
pop esi
pop ebx
pop ebp
ret 16
farm_thread:
push 0
call GetModuleHandle
mov dword ptr [farmhinst], eax
farm_thread_reg_class:
mov dword ptr [farmwc.style], CS_HREDRAW+CS_VREDRAW+CS_GLOBALCLASS
mov dword ptr [farmwc.lpfnWndProc], offset farm_thread_wndproc
mov dword ptr [farmwc.cbClsExtra], 0
mov dword ptr [farmwc.cbWndExtra], 0
mov eax, dword ptr [farmhinst]
mov dword ptr [farmwc.hInstance], eax
push IDI_APPLICATION
push 0
call LoadIcon
mov dword ptr [farmwc.hIcon], eax
push IDC_CROSS
push 0
call LoadCursor
mov dword ptr [farmwc.hCursor], eax
mov dword ptr [farmwc.hbrBackground], COLOR_WINDOW+1
mov dword ptr [farmwc.lpszMenuName], 0
mov dword ptr [farmwc.lpszClassName], offset farmcname
push offset farmwc
call RegisterClass
push 0
push dword ptr [farmhinst]
push 0
push 0
push CW_USEDEFAULT
push CW_USEDEFAULT
push CW_USEDEFAULT
push CW_USEDEFAULT
push WS_OVERLAPPEDWINDOW
push offset farmtname
push offset farmcname
push 0
call CreateWindowEx
mov dword ptr [farmhwnd], eax
push SW_SHOWNORMAL
push dword ptr [farmhwnd]
call ShowWindow
push dword ptr [farmhwnd]
call UpdateWindow
farm_thread_msg_loop:
push 0
push 0
push 0
push offset farmmsg
call GetMessage
cmp eax, 0
jz farm_thread_end_loop
push offset farmmsg
call TranslateMessage
push offset farmmsg
call DispatchMessage
jmp farm_thread_msg_loop
farm_thread_end_loop:
push dword ptr [farmmsg.wParam]
call ExitThread
farm_thread_wndproc:
push ebp
mov ebp, esp
push ebx
push esi
push edi
cmp dword ptr [ebp+0Ch], WM_DESTROY
jz farm_thread_wndproc_wmdestroy
jmp farm_thread_wndproc_defwndproc
farm_thread_wndproc_wmdestroy:
push 0
call PostQuitMessage
sub eax, eax
jmp farm_thread_wndproc_finish
farm_thread_wndproc_defwndproc:
push dword ptr [ebp+14h]
push dword ptr [ebp+10h]
push dword ptr [ebp+0Ch]
push dword ptr [ebp+08h]
call DefWindowProc
farm_thread_wndproc_finish:
pop edi
pop esi
pop ebx
pop ebp
ret 16
smith_thread:
push 0
call GetModuleHandle
mov dword ptr [smithhinst], eax
smith_thread_reg_class:
mov dword ptr [smithwc.style], CS_HREDRAW+CS_VREDRAW+CS_GLOBALCLASS
mov dword ptr [smithwc.lpfnWndProc], offset smith_thread_wndproc
mov dword ptr [smithwc.cbClsExtra], 0
mov dword ptr [smithwc.cbWndExtra], 0
mov eax, dword ptr [smithhinst]
mov dword ptr [smithwc.hInstance], eax
push IDI_APPLICATION
push 0
call LoadIcon
mov dword ptr [smithwc.hIcon], eax
push IDC_CROSS
push 0
call LoadCursor
mov dword ptr [smithwc.hCursor], eax
mov dword ptr [smithwc.hbrBackground], COLOR_WINDOW+1
mov dword ptr [smithwc.lpszMenuName], 0
mov dword ptr [smithwc.lpszClassName], offset smithcname
push offset smithwc
call RegisterClass
push 0
push dword ptr [smithhinst]
push 0
push 0
push CW_USEDEFAULT
push CW_USEDEFAULT
push CW_USEDEFAULT
push CW_USEDEFAULT
push WS_OVERLAPPEDWINDOW
push offset smithtname
push offset smithcname
push 0
call CreateWindowEx
mov dword ptr [smithhwnd], eax
push SW_SHOWNORMAL
push dword ptr [smithhwnd]
call ShowWindow
push dword ptr [smithhwnd]
call UpdateWindow
smith_thread_msg_loop:
push 0
push 0
push 0
push offset smithmsg
call GetMessage
cmp eax, 0
jz smith_thread_end_loop
push offset smithmsg
call TranslateMessage
push offset smithmsg
call DispatchMessage
jmp smith_thread_msg_loop
smith_thread_end_loop:
push dword ptr [smithmsg.wParam]
call ExitThread
smith_thread_wndproc:
push ebp
mov ebp, esp
push ebx
push esi
push edi
cmp dword ptr [ebp+0Ch], WM_DESTROY
jz smith_thread_wndproc_wmdestroy
jmp smith_thread_wndproc_defwndproc
smith_thread_wndproc_wmdestroy:
push 0
call PostQuitMessage
sub eax, eax
jmp smith_thread_wndproc_finish
smith_thread_wndproc_defwndproc:
push dword ptr [ebp+14h]
push dword ptr [ebp+10h]
push dword ptr [ebp+0Ch]
push dword ptr [ebp+08h]
call DefWindowProc
smith_thread_wndproc_finish:
pop edi
pop esi
pop ebx
pop ebp
ret 16
hunt_thread:
push 0
call GetModuleHandle
mov dword ptr [hunthinst], eax
hunt_thread_reg_class:
mov dword ptr [huntwc.style], CS_HREDRAW+CS_VREDRAW+CS_GLOBALCLASS
mov dword ptr [huntwc.lpfnWndProc], offset hunt_thread_wndproc
mov dword ptr [huntwc.cbClsExtra], 0
mov dword ptr [huntwc.cbWndExtra], 0
mov eax, dword ptr [hunthinst]
mov dword ptr [huntwc.hInstance], eax
push IDI_APPLICATION
push 0
call LoadIcon
mov dword ptr [huntwc.hIcon], eax
push IDC_CROSS
push 0
call LoadCursor
mov dword ptr [huntwc.hCursor], eax
mov dword ptr [huntwc.hbrBackground], COLOR_WINDOW+1
mov dword ptr [huntwc.lpszMenuName], 0
mov dword ptr [huntwc.lpszClassName], offset huntcname
push offset huntwc
call RegisterClass
push 0
push dword ptr [hunthinst]
push 0
push 0
push CW_USEDEFAULT
push CW_USEDEFAULT
push CW_USEDEFAULT
push CW_USEDEFAULT
push WS_OVERLAPPEDWINDOW
push offset hunttname
push offset huntcname
push 0
call CreateWindowEx
mov dword ptr [hunthwnd], eax
push SW_SHOWNORMAL
push dword ptr [hunthwnd]
call ShowWindow
push dword ptr [hunthwnd]
call UpdateWindow
hunt_thread_msg_loop:
push 0
push 0
push 0
push offset huntmsg
call GetMessage
cmp eax, 0
jz hunt_thread_end_loop
push offset huntmsg
call TranslateMessage
push offset huntmsg
call DispatchMessage
jmp hunt_thread_msg_loop
hunt_thread_end_loop:
push dword ptr [huntmsg.wParam]
call ExitThread
hunt_thread_wndproc:
push ebp
mov ebp, esp
push ebx
push esi
push edi
cmp dword ptr [ebp+0Ch], WM_DESTROY
jz hunt_thread_wndproc_wmdestroy
jmp hunt_thread_wndproc_defwndproc
hunt_thread_wndproc_wmdestroy:
push 0
call PostQuitMessage
sub eax, eax
jmp hunt_thread_wndproc_finish
hunt_thread_wndproc_defwndproc:
push dword ptr [ebp+14h]
push dword ptr [ebp+10h]
push dword ptr [ebp+0Ch]
push dword ptr [ebp+08h]
call DefWindowProc
hunt_thread_wndproc_finish:
pop edi
pop esi
pop ebx
pop ebp
ret 16
end start
|
|
|
02-18-2006, 09:02 PM
|
#2 (permalink)
|
|
Moderator
Join Date: May 2002
Location: us.ca
Posts: 4,487
|
what language is that?
|
|
|
02-18-2006, 11:39 PM
|
#3 (permalink)
|
|
Newbie
Join Date: Jun 2002
Location: Denmark
Posts: 1,709
|
It's assembly, or atleast looks like it.. But it dosn't strike me as beeing x86 assembly.. It could be some heigher form of assembly..
But then again it could be the heavy use of data befor any real code, that messes up my perspective.
Usualy you would use far more refference to available registers, all these single arguments push, call, jz instructions suggests theres a deafult register beeing addressed, like a0 on alpha.
|
|
|
02-19-2006, 09:48 AM
|
#4 (permalink)
|
|
Jedi Master
Join Date: Feb 2006
Location: Denver, CO
Posts: 15
|
SDE:
It's X86 Assembly language.
Redhead:
What you're seeing that's potentially confusing is that I'm setting up calls to Windows XP API functions. It can be pretty shocking to see that in ASM for the first time, all the bowing and scraping, etc...
|
|
|
02-19-2006, 07:03 PM
|
#5 (permalink)
|
|
Jedi Master
Join Date: Feb 2006
Location: Denver, CO
Posts: 15
|
The situation has been resolved - I was taking the wrong approach.
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -8. The time now is 09:53 PM.
|
Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
|
 |
|