Welcome, Guest. Please login or register.

Author Topic: Stupid question about if it's possible to link and create two separate executables  (Read 7017 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline JoseTopic starter

  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 2871
    • Show only replies by Jose
Is it possible to have two different programs recognize each others variables with linking but still be compiled to two different executables?
I know it sounds stupid but the reason is that I want a created process to be created after the main task and I want it to recognize some global variables between the two.
Now if you know another way of creating a process in
[Edit] I handled this without problems with V36 of course...
\\"We made Amiga, they {bleep}ed it up\\"
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show only replies by Karlos
I don't have the documentation handy, but there must be a way to create a Process pre v36 without trying to resort to this kind of thing.

Do you absolutely need pre v36 compatibility anyway?
int p; // A
 

Offline thorrin

  • Newbie
  • *
  • Join Date: Jun 2003
  • Posts: 46
    • Show only replies by thorrin
    • http://thorrin.hopto.org
Well, Im not too good with AmigaOS, but in VxWorks you can pass messages between tasks.  A message is a type of interrupt that will 'wake up' a seperate pending task.  Im sure something like this exists in the AmigaOS.

Or if you want to do some brute force coding (which would be very bad), you could hard code a place in memory to hold the variables, but you would probably overwrite something else in the process...  ie:  there is no guarantee that some other program wouldnt be using the exact memory.

In 'C', something like this would work... say you have a variable that you want to share between the tasks, you could store that variable at some address (say 0x8000 0000). To access the var, you could do some funky pointer stuff:

    *((int*)(0x8000000)) = 5  //store 5 at 0x8000 0000 in program 1
    x = *((int*)(0x8000000))  //get what is at 0x8000 0000 in program 2

this solution is really only good for embedded programming... something where you KNOW there wont be a collision.  But it will work.  Trying this on your amiga may crash it in ways you cant imagine :-P

-Thorrin
The best part about it was when I got paid...
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show only replies by Karlos
@Thorrin

That type of messaging would be extremely hit and miss under AmigaOS. You aren't supposed to use any absolute address (apart from when banging hardware regusters) and sharing variables in this way would be dangerous even if you could. There is no "ownership" possible - one thread may change the variable without the other being aware right in the middle of it doing something with it.

Fortunately amigaos does allow you to create message ports that can be registered (by name) with the system to allow interprocess communication by passing (by reference) messages between ports.

Still, neither of these seem particularly relevant to Jose's problem. There must be a way to create processes in pre v36 AmigaOS without having to load a segment list. How does CreateNewProc() do it?
int p; // A
 

Offline bloodline

  • Master Sock Abuser
  • Hero Member
  • *****
  • Join Date: Mar 2002
  • Posts: 12114
    • Show only replies by bloodline
    • http://www.troubled-mind.com
Quote

Karlos wrote:
@Thorrin

That type of messaging would be extremely hit and miss under AmigaOS. You aren't supposed to use any absolute address (apart from when banging hardware regusters) and sharing variables in this way would be dangerous even if you could. There is no "ownership" possible - one thread may change the variable without the other being aware right in the middle of it doing something with it.

Fortunately amigaos does allow you to create message ports that can be registered (by name) with the system to allow interprocess communication by passing (by reference) messages between ports.

Still, neither of these seem particularly relevant to Jose's problem. There must be a way to create processes in pre v36 AmigaOS without having to load a segment list. How does CreateNewProc() do it?


Maybe he/you could look at the AROS code :-)

Offline Argo

  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 3219
    • Show only replies by Argo
Message ports ala AREXX. Is that what you are talking about?
Couldn't you pass the variable values between programs like that. It wouldn't be sharing the same variable, just sharing the same information between programs.
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show only replies by Karlos
@bloodline.

Yeah, I wish. These days I don't seem to have the time to do any real coding (all this php/mysql/javascript stuff is interesting but hardly as much fun as C++) - and when I do have time I'm usually to bloody knackered.

Having a job killed my inner child :-(
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show only replies by Karlos
@Argo

Well, I was referring to exec's MsgPort/Message system. Your process can create a MsgPort and tell exec to add your new message port to its list of public ports, allowing other processes to look it up. The messages themselves are low level C structures that can be passed from one process to another process via these ports. There is no constraints on what that message can contain, so its quite a useful system. Processes can wait for messages to arrive at their ports and messages are automatically queued so that they are not lost if the process cannot process the message immediately.

A classic example is Intuition, which uses the system to send input events to the a window etc.

Arrex's ports are conceptually similar but not quite the same thing.
int p; // A
 

Offline thorrin

  • Newbie
  • *
  • Join Date: Jun 2003
  • Posts: 46
    • Show only replies by thorrin
    • http://thorrin.hopto.org
That sounds like what I was trying to describe in the VxWorks scenario.  I would imagine that all real time/multitasking operating systems have the same type of functionality.  I just didnt know what it was in amigaos.  In this case, he could create a structure as the message with the new variable values and pass THAT to the other task.

The only issue that I can think of doing it this way is if both tasks can modify variables.  You would have to have some kind of way to ensure that there aren't 2 variable change requests being sent at the same time.

And yeah, I know that the direct memory thing is BAD :-D, but it was a useful bit of info to pass on and in some cases its necessary (like you said... banging the HW)
   
-Thorrin

Quote

Karlos wrote:
@Argo

Well, I was referring to exec's MsgPort/Message system. Your process can create a MsgPort and tell exec to add your new message port to its list of public ports, allowing other processes to look it up. The messages themselves are low level C structures that can be passed from one process to another process via these ports. There is no constraints on what that message can contain, so its quite a useful system. Processes can wait for messages to arrive at their ports and messages are automatically queued so that they are not lost if the process cannot process the message immediately.

A classic example is Intuition, which uses the system to send input events to the a window etc.

Arrex's ports are conceptually similar but not quite the same thing.
 
The best part about it was when I got paid...
 

Offline JoseTopic starter

  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 2871
    • Show only replies by Jose
Hi. 8-)  Well no, I don´t absolutely need pre v36 compatibility but it would be cool to have it, it could mean when my app is done it will run on more machnines. I won't sacrifice it because of that though...
Message ports, yeah, I know. I'm currently using signals in some parts wich are faster :-) But yes, when the need is passing variables I guess sending a message would be the only way. Still it would be nice to have a process created without needing to have to load it from disk. I also found some stuff about separate compilation of two executables but with linking in some Linux discussion groups (no I'm not into Linux at all I just found that...) and though that could be another solution. But maybe that's not possible with AmigaOS. If I remember correctly with AmigaOS some locations are resolved at load time.


Anyway, what I want the created process to know about is the mainprocess's (the one that created it) task structure so that it can send it a signal. I guess I can do a FindTask(NULL) on the main process and send the result as a message to the second one, wich I'd have to locate first with FindTask (name)... I was just hoping that there would be another way...
\\"We made Amiga, they {bleep}ed it up\\"
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Quote
Is it possible to have two different programs recognize each others variables with linking but still be compiled to two different executables?
I know it sounds stupid but the reason is that I want a created process to be created after the main task and I want it to recognize some global variables between the two.

No, you need to somehow pass ptr to some structure you use to share data. Convinient and flexible way is to use messages, it allows great dynamic control of the subprocess: My IPC example

Some uglier hacks use tc_UserData or pr_ExitData of the just created struct Process. If you do this, remember to enclose CreateNewProc + field poking in Forbid/Permit or else the code gets to run before you have chance to poke the ptr in.

Quote
Now if you know another way of creating a process in

The answer would be fake seglist passed to CreateProc.

Something like:
Code: [Select]

#include <exec/execbase.h>
#include <dos/dos.h>

#include <proto/exec.h>
#include <proto/dos.h>

#ifdef __GNUC__
# pragma pack(2)
#endif
struct fakeseg
{
  ULONG size;
  BPTR  next;
  UWORD jmp;
  APTR  myfunc;
};
#ifdef __GNUC__
# pragma pack()
#endif

extern struct ExecBase *SysBase;

BPTR allocfakeseg(void (*func)(void))
{
  struct fakeseg *seg = AllocMem(sizeof(*seg),
                                 MEMF_PUBLIC);
  if (seg)
  {
    seg->size   = 16;
    seg->next   = 0;
    seg->jmp    = 0x4EF9;
    seg->myfunc = (APTR) func;

    if (SysBase->LibNode.lib_Version >= 37)
    {
      CacheClearE(seg, sizeof(*seg), CACRF_ClearI);
    }
    else
    {
      /* Call some asm cacheclear function that handles possible
         020/030 caches. 040+ is only supported on 2.0+. */

      /* flushcaches(); */
    }    

    return MKBADDR(&seg->next);
  }

  return 0;
}

void freefakeseg(BPTR segptr)
{
  if (segptr)
  {
    struct fakeseg *seg = (APTR) (((ULONG *) BADDR(segptr)) - 1);

    FreeMem(seg, sizeof(*seg));
  }
}

void code(void)
{
  /* ... */
}

int main(void)
{
  BPTR seg;

  seg = allocfakeseg(code);
  if (seg)
  {
    /* use seg */

    freefakeseg(seg);
  }

  return 0;
}

Obviously you still need to provide proper syncronization so that you don't call freefakeseg prematurely.
 

Offline bloodline

  • Master Sock Abuser
  • Hero Member
  • *****
  • Join Date: Mar 2002
  • Posts: 12114
    • Show only replies by bloodline
    • http://www.troubled-mind.com
Just a quick question José...

Why don't you allocate some memory (making sure to set the MEMF_PUBLIC flag ;-)), then reserve the first word for use as a flag.
Then pass a pointer to this memory block to your child task.
Now both programs can use the memory block, but make sure you check the first word before you read/write the memory block.

If you want to read/write the memory block, read the first word, if it contains -1 (or something) then the memory block is in use, and you can't use it.

If it reads 0, then set the first word to -1 and use the memory block... once you finish using it write 0 to the first word.

That should do what you want to do.

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show only replies by Karlos
@bloodline

Slight variation on that - simply create a struct that has all your shared globals in it and pass a pointer to that structure (via a Message) to the other task.

That struct could also contain a SignalSemaphore as part of its definition which would be used solve the concurrency issue.
int p; // A
 

Offline bloodline

  • Master Sock Abuser
  • Hero Member
  • *****
  • Join Date: Mar 2002
  • Posts: 12114
    • Show only replies by bloodline
    • http://www.troubled-mind.com
Quote

Karlos wrote:
@bloodline

Slight variation on that - simply create a struct that has all your shared globals in it and pass a pointer to that structure (via a Message) to the other task.

That struct could also contain a SignalSemaphore as part of its definition which would be used solve the concurrency issue.


Hmmm... yeah that makes more sense... I got to stop thinking ASM :-)

Offline thorrin

  • Newbie
  • *
  • Join Date: Jun 2003
  • Posts: 46
    • Show only replies by thorrin
    • http://thorrin.hopto.org
Dern, y'all are going to make me get an AmigaOne and start coding up some stuff...  This all sounds like good fun.

-Thorrin
The best part about it was when I got paid...