THR_EXIT message

GFA, ASM, STOS, ...

Moderators: simonsunnyboy, Mug UK, Zorro 2, Moderator Team

Post Reply
OL
Atari Super Hero
Atari Super Hero
Posts: 589
Joined: Fri Apr 01, 2005 6:59 am
Contact:

THR_EXIT message

Post by OL »

Hello

At end thread (create by shel_write with Magic), application should receive THR_EXIT

regarding toshyp documentation : https://freemint.github.io/tos.hyp/en/e ... l#THR_EXIT
in msg[3] should have AES ID of thread terminated, but if thread have not call AES does message THR_EXIT is sent ? If yes what there is in msg[3] ? If no is there another message sent to application such CH_EXIT ?

Thanks

Olivier
OL
ThorstenOtto
Atari God
Atari God
Posts: 1483
Joined: Sun Aug 03, 2014 5:54 pm

Re: THR_EXIT message

Post by ThorstenOtto »

Quickly looking through the source https://github.com/th-otto/MagicMac/blo ... in.s#L2763 It looks like MagiC always calls init_APPL for the thread, which means it gets an AES id even if it does not do any AES calls.
gstoll
Obsessive compulsive Atari behavior
Obsessive compulsive Atari behavior
Posts: 111
Joined: Sun Feb 17, 2008 4:29 pm

Re: THR_EXIT message

Post by gstoll »

ThorstenOtto wrote: Sun May 09, 2021 6:14 am It looks like MagiC always calls init_APPL for the thread
init_APPL() inits only the APPL structure. For me it looks that the docu is wrong. It is the application ID in msg[3] and not the AES ID. That is what I also see in the source from Fiffi.
ThorstenOtto
Atari God
Atari God
Posts: 1483
Joined: Sun Aug 03, 2014 5:54 pm

Re: THR_EXIT message

Post by ThorstenOtto »

gstoll wrote: Sun May 09, 2021 7:48 am init_APPL() inits only the APPL structure.

For me it looks that the docu is wrong. It is the application ID in msg[3] and not the AES ID. That is what I also see in the source from Fiffi.
Yes, and that's the structure used by AES. And amongst ohers, it sets the ap_id: https://github.com/th-otto/MagicMac/blo ... ain.s#L916
It is the application ID in msg[3] and not the AES ID.
No. ap_id *is* the AES ID. appl_init() does not generate a new ID, it just copies the ap_id from the current application to the output parameters. The (GEMDOS) process id is p_procid in the process structure. And it is the ap_id that is send in the THR_EXIT message: https://github.com/th-otto/MagicMac/blo ... in.s#L9543
gstoll
Obsessive compulsive Atari behavior
Obsessive compulsive Atari behavior
Posts: 111
Joined: Sun Feb 17, 2008 4:29 pm

Re: THR_EXIT message

Post by gstoll »

ThorstenOtto wrote: Sun May 09, 2021 8:03 am No. ap_id *is* the AES ID. appl_init() does not generate a new ID, it just copies the ap_id from the current application to the output parameters.
OK, than it is not clear for me what is the difference between application ID and AES ID.
ThorstenOtto
Atari God
Atari God
Posts: 1483
Joined: Sun Aug 03, 2014 5:54 pm

Re: THR_EXIT message

Post by ThorstenOtto »

There is none. It's the AES id that is returned by shel_write(SHW_THR_CREATE)
OL
Atari Super Hero
Atari Super Hero
Posts: 589
Joined: Fri Apr 01, 2005 6:59 am
Contact:

Re: THR_EXIT message

Post by OL »

Thanks for all this answers, very interesting

Do you think some thread could try to access to AES without doing appl_init() thinking appl_init() have already done ? All example I can found in Magic source looks like always appl_init() is done by thread and it is recommendation done by Andreas.

Olivier
OL
ThorstenOtto
Atari God
Atari God
Posts: 1483
Joined: Sun Aug 03, 2014 5:54 pm

Re: THR_EXIT message

Post by ThorstenOtto »

I'm not sure, since MagiC is the only OS that supports AES threads, i never used it. However, without calling appl_init, at least the bindings from Pure-C won't work i think, because they also write the returned ID to the global array. You could maybe look at the source of the mgcopy application, which uses threads IIRC.
OL
Atari Super Hero
Atari Super Hero
Posts: 589
Joined: Fri Apr 01, 2005 6:59 am
Contact:

Re: THR_EXIT message

Post by OL »

Thanks Otto

In all case for this PureC aes binding can't be used as it need use mt_xxx aes binding with for each thread there own global array.
ThorstenOtto wrote: Sun May 09, 2021 5:09 pm I'm not sure, since MagiC is the only OS that supports AES threads, i never used it. However, without calling appl_init, at least the bindings from Pure-C won't work i think, because they also write the returned ID to the global array. You could maybe look at the source of the mgcopy application, which uses threads IIRC.
Thread is very interesting for my point of view, as it can be highly efficient to use for some software that not want wait for event and prefer do calculation such like video player, game, math calculator ....

So now not only MagiC is able to do it but for 1 month I have implement it in MyAES, I just finish to try to be more compatible.

Finally for simplification and memory used THR_EXIT will be sent only if thread do itself an appl_init() else application will received CH_EXIT only, I think it is enough, appl_exit() is not need as in Magic example. Not yet implement shel_write(END_THREAD...) don't know really if it is useful.

Olivier
OL
ThorstenOtto
Atari God
Atari God
Posts: 1483
Joined: Sun Aug 03, 2014 5:54 pm

Re: THR_EXIT message

Post by ThorstenOtto »

OL wrote: Mon May 10, 2021 6:06 am Finally for simplification and memory used THR_EXIT will be sent only if thread do itself an appl_init()
Magic always sends THR_EXIT.
else application will received CH_EXIT only,
I think that is wrong. CH_EXIT is meant to be sent when the application terminates, not a single thread.
not yet implement shel_write(END_THREAD...) don't know really if it is useful.
Depends on what the thread is doing, but it is always helpful to have control over it, and terminate it if needed. Imagine a thread for example that receives network data, and you are about to close the connection the server.
OL
Atari Super Hero
Atari Super Hero
Posts: 589
Joined: Fri Apr 01, 2005 6:59 am
Contact:

Re: THR_EXIT message

Post by OL »

ThorstenOtto wrote: Mon May 10, 2021 10:30 am
OL wrote: Mon May 10, 2021 6:06 am Finally for simplification and memory used THR_EXIT will be sent only if thread do itself an appl_init()
Magic always sends THR_EXIT.
Ok, but in all case I have seen there is always an appl_init() in thread so if thread do application should receive this message, ok it's not exactly the same so I'm going to try do same. I see 2 way for do it, or do an appl_init at thread start as Magic or do a list of thread.
As we can see in Magic source, AES do an appl_init() then thread do again an appl_init() even if not use AES this is very strange, and no appl_exit() for thread. Does a thread doing appl_init() should appear in aes list application ? For me yes but as only an appl_init() is done and no AES event used probably should not but AES is not able to know what thread will do. For me this appl_init() is a simple way to manage THR_EXIT message but probably not a very good design. In all case I'm going to fix this. Thanks
else application will received CH_EXIT only,
I think that is wrong. CH_EXIT is meant to be sent when the application terminates, not a single thread.
Ok try to replace CH_EXIT by THR_EXIT
not yet implement shel_write(END_THREAD...) don't know really if it is useful.
Depends on what the thread is doing, but it is always helpful to have control over it, and terminate it if needed. Imagine a thread for example that receives network data, and you are about to close the connection the server.
In this case END_THREAD this is the thread that request to stop itself, but as I know (perhaps I'm wrong) there is no protocol with application, why simply not return from routine thread ? I see possible this thread as launch thread itself and not want leave before thread child out, as memory is fully shared it is quite easy for thread and application to speak together without help of AES
OL
Post Reply

Return to “Coding”