Recent Posts

Pages: [1] 2 3 ... 10
1
Irvine Book Questions. / Re: Use CreateThread in MASM Program
« Last post by jj2007 on Today at 12:47:02 PM »
You solve the calling proc exiting before the thread starts by using a spinlock to delay the caller's exit

Right, you can do that - WaitForxx etc. But we need to distinguish two important uses for CreateThread imho:

1. You are not sure if the threadproc succeeds at all, so you use a thread and a timeout to avoid a hanging application -> spinlock, WaitForxx;

2. You know that the thread proc will take some time, but you don't want to be blocked -> completely asynchronous process, the thread starts but you exit immediately from the calling procedure, and when the thread has finished, you'll get a notification via WM_PRIVATE_WHATEVER.

In case 1, you can pass the addresses of local variables to the thread, in case 2 you cannot.
2
Irvine Book Questions. / Re: Use CreateThread in MASM Program
« Last post by felipe on Today at 12:45:28 PM »
remember that we all start somewhere. You were a noob once, too. Please don't forget that.  ;)
Not true actually, times changes, it would be sad that every thing would be the same as years ago. I guess that teachers don't put emphasis on that fact, but certanly things are different (probably every time). So take note: don't make wrong assumptions, if you want to actually learn from this forum you should respect some rules.
Now, of course you can think what you want, i'm just telling that generalizations like the one above is not really applicable. So the simple, easy and good thing would be saying: "We have all been noob once, but very differents noob".
 :biggrin:
3
The Campus / Re: Bundle and Play XM File As Resource
« Last post by DavidB on Today at 12:37:34 PM »
Hi David,

This example plays a XM music module from the resource.

Hi DavidB,

You can use the fda ( file data assembler ) tool supplied with the Masm32 package to convert any binary file to a MS COFF object module.
Great! I used to the fda tool to convert the XM file, and as a result, I got an "inc" and "obj" file, but I cannot figure out what I am actually supposed to do with them. The example that Siekmanski provided is great, but it does not have either an inc or obj file. Also, it does not appear to have been built with Visual Studio. I would assume that from here, I would have to convert these two files to a resource file in some way?
4
Irvine Book Questions. / Re: Use CreateThread in MASM Program
« Last post by hutch-- on Today at 12:31:10 PM »
You solve the calling proc exiting before the thread starts by using a spinlock to delay the caller's exit until the thread has successfully started and the argument content has been passed to it. It tends to only be a problem if the caller procedure is being hit reasonably fast, a longer procedure that does not exit quickly does not have the problem.
5
Irvine Book Questions. / Re: Use CreateThread in MASM Program
« Last post by DavidB on Today at 12:13:21 PM »
And again, you confirm that you are stinking lazy, unwilling to read the FM, and waiting for people to spoon-feed you (otherwise you would have noticed that I supplied a full example above). You won't get far with this attitude. Btw there is a "no homework" rule in this forum.
I saw the whole example. I just did not notice that it was from you. That was actually my mistake, so I apologize.

As for the "no homework" policy, I am well aware of it. While this question is related to a homework assignment, the threading aspect of my project is not a requirement. For my final project, I can create anything I want as long as I satisfy a certain set of requirements, but I am allowed to add extra stuff if I want. I have already satisfied the project's minimum requirements to get the grade. This multi-threading business that I am trying to do would just be a nice touch. So please don't make assumptions. And most importantly, remember that we all start somewhere. You were a noob once, too. Please don't forget that.  ;)
6
Irvine Book Questions. / Re: Use CreateThread in MASM Program
« Last post by jj2007 on Today at 12:05:49 PM »
There is a tool called "Google" that can provide you with "About 1,600,000 results" on "CreateThread". If that is not enough, there is a second tool called "Forum search" that, if you can find it (e.g. by clicking here), will give you 24 threads dealing with "CreateThread". All this requires a skill that has become rare in the era of YouTube tutorials, it's called "reading".
Congratulations. You have officially contributed nothing useful to this conversation.

And again, you confirm that you are stinking lazy, unwilling to read the FM, and waiting for people to spoon-feed you (otherwise you would have noticed that I supplied a full example above). You won't get far with this attitude. Btw there is a "no homework" rule in this forum.
7
Good article, the data size difference makes 64 bit bigger and on any given hardware, bigger data equals slower operation. Your gains in 64 bit is memory and if you are working with big data, it is the way to go as > 2 gig in 32 bit is a pain to deal with. Another factor is that with twice as many registers you save stack entry and exit overhead in many instances, particularly with an argument list of 4 or less where you use registers to pass the data.

Writing in 64 bit is a different brain that 32 bit and the quicker the assumptions of 32 are dropped, the better the 64 bit code will be. As it was with MS-DOS going into Win3.?, in many instances well written 16 bit DOS kicked its arse so for exactly the same reason, well written 32 bit code will often beat normal 64 bit code but over time the gap will narrow as compilers and programmers get better at 64 bit code but 32 bit code can never close the gap at what 64 bit can routinely do with big memory and more registers.
8
Irvine Book Questions. / Re: Use CreateThread in MASM Program
« Last post by DavidB on Today at 11:48:42 AM »
There is a tool called "Google" that can provide you with "About 1,600,000 results" on "CreateThread". If that is not enough, there is a second tool called "Forum search" that, if you can find it (e.g. by clicking here), will give you 24 threads dealing with "CreateThread". All this requires a skill that has become rare in the era of YouTube tutorials, it's called "reading".
Congratulations. You have officially contributed nothing useful to this conversation. Now please, go away and let people actually be helpful.  ;)

David,

With Irvine code I cannot help you but using CreateThread means looking up its arguments and creating a new procedure that the new thread starts in. The old Win32.hlp has the reference material but if you don't have that you can look up the API in MSDN and it will refer you to the format of the procedure which is a single argument. In 32 bit its a DWORD, in 64 bit its a QWORD. If you need to pass a lot of data (more than 1 arg) you pass the address of an array OR structure that contains the data you want to pass.
I think a majority of the issue that I was having at the time of writing this post was the fact that I was limiting myself to the Irvine libraries. I did not realize that I would have to use the MASM32 SDK to achieve this. That's not really a problem though. Thanks for providing an explanation that is easier to understand.

CreateThread is pretty simple
i quite often use it with most of the arguments = 0

Code: [Select]
    INVOKE  CreateThread,0,0,MyThread,0,0,0
the 1st, 2nd, and 5th arguments are rarely needed
the 4th and 6th arguments are of possible interest....

the 6th argument may be used to point to a variable that receives the thread ID
the 4th argument may be used to pass an argument to the thread

Code: [Select]
.DATA?

dwThreadId dd ?

.CODE

    INVOKE  CreateThread,0,0,MyThread,12345678h,0,offset dwThreadId

.
.
.

MyThread PROC

    mov     eax,[esp+4]                ;EAX = 12345678h
.
.
.
    INVOKE  ExitThread,eax

MyThread ENDP

at the bottom of this page are a few related functions of interest...

https://msdn.microsoft.com/en-us/library/windows/desktop/ms682453%28v=vs.85%29.aspx

avoid using TerminateThread
avoid using a MyThread proc with a stack frame (no arguments or local variables)
Thank you! I had actually seen the MSDN page that you are referring to earlier, and read the entire thing, but your short, concise explanation was much more beneficial to me.

There are a number of precautions to take when using multiple threads, and it also depends on the type of application we are dealing with (console, windows, service, etc.)
In my quoted example, the main issue I had to deal with, as far as threading was concerned, was using "printf" from multiple threads. printf is not thread safe. While in the SDK example that I took as inspiration, they simply did not use the printf, obviously for that reason, I decided to keep with it but allow access to only 1 thread at a time by using a semaphore.
The program that I am writing is a console application. Basically, I want to have a procedure in a separate thread that is used for repeatedly drawing in the console every x seconds, and in the main thread, have a procedure which repeatedly waits for keyboard input from the user using Irvine's "ReadChar."
9
masm64rt.inc includes kernel32.inc, which declares GetSystemInfo as __imp_GetSystemInfo and is thus ready to use. printf is not declared, but the include file msvcrt.inc is also included by masm64rt.inc, which does declare vc_printf. The idea was to avoid name conflicts and thus give all functions from the CRT the prefix "cv_" (for masm32 it is "crt_" BTW). Your declaration of printf will be accepted by MASM, but the linker cannot resolve that symbol later, because there is no library associated with it  ==> use vc_printf instead.
10
Hello everyone,

I am puzzled as to why ml will complain about redefining some symbols and not others.  Consider the following code snippet
Quote
[
include \masm32\include64\masm64rt.inc

printf PROTO :QWORD , :VARARG
GetSystemInfo PROTO :QWORD


ml complains with this error "symbol redefinition : __imp_GetSystemInfo

But,  it's quite happy with the printf PROTO.

What's the difference?  I know the two are in two different iimplibs and dlls, but why does ml handle them differently?

Thanks for any clarity you can provide.

Mark Allyn
Pages: [1] 2 3 ... 10