News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

asynchronous file I/O

Started by sinsi, February 12, 2010, 10:19:41 AM

Previous topic - Next topic

redskull

Whether you call RET or ExitThread, the same thing happens (the thread is ended).  The problem for C++ is that destructors are automatically added *at the end* (after the ExitThread call); you code ends up doing this:

;Do Stuff
CALL ExitThread               ---> Ends the thread
CALL DestructorFunction   --->  Never called!

It's not really applicable to asm (or C), or even C++ unless you have OS things reserved (handles, semaphore, objects).  You can sometimes dupe the compiler by putting braces around the class:

MyThread() {
   {
   MyClass MyObj
   
   Do Stuff
   
   }            <-- Generates call to desctructor
   ExitThread()

-r
Strange women, lying in ponds, distributing swords, is no basis for a system of government

jj2007

Quote from: qWord on February 12, 2010, 07:17:40 PM
QuoteWhen this function is called (either explicitly or by returning from a thread procedure)...
IMO its clear: there is no differenc between ExitThread and RET. Using OllyDbg you can see that both methods end up in a call to
RtlExitUserThread (ntdll).


Actually, Olly 1.1 gets stuck in the thread, but I could convince Olly 2. This is what I found, confirming more or less what you write:

QuoteMyThread proc singleArg:DWORD
  invoke Sleep, 1000
  mov TheFlag, 321
  return singleArg
  ; instead of invoke ExitThread, singleArg; translates into:
  mov eax, singleArg
  leave
  retn 4      ; 40110A
;  ...
  push eax      ; 7C80B683
  call ExitThread
MyThread endp

So a simple ret does indeed the same job.

qWord

Quote from: jj2007 on February 12, 2010, 11:00:28 PMActually, Olly 1.1 gets stuck in the thread
I've had the same problems until some on told me that this problem is caused by the plugin (which injects code in the debugged process) for decoding SSE-registers -> disable options->registers->'decode SSE registers'.

qword
FPU in a trice: SmplMath
It's that simple!

oex

Quote from: jj2007 on February 12, 2010, 05:54:50 PM

invoke CreateThread, 0, 0, offset MyThread, 123, 0, offset ThreadID


When I used to code in VC *shudder* I seem to remember I used to pass an address as the thread value (123), I see Dave creates a global var to hold extra data.... I think my way is better but I'm open to you guys criticising my methology in the pursuit of truth....


mov esi, alloc(32)
mov [esi+X], Data You Want To Pass (<---- You might find this syntax errors :D)
invoke CreateThread, 0, 0, offset MyThread, esi, 0, offset ThreadID


No real difference I can see except readability, filesize, locality?
We are all of us insane, just to varying degrees and intelligently balanced through networking

http://www.hereford.tv