Welcome, Guest. Please login or register.

Author Topic: Libraries & CreateNewProc  (Read 3220 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: Libraries & CreateNewProc
« on: August 31, 2004, 09:33:18 PM »
It's always been my understanding that a complete program, which may contain several concurrent threads can all share resources declared within that program* (including library bases etc).

I've never had to open a library for a process created by my main task and never encountered any problems as a consequence.

Just make sure you properly (Semaphore) protect any resouces such as IO handles etc. that you intend to share between threads and all should be OK.

*scope permitting of course ;-)
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: Libraries & CreateNewProc
« Reply #1 on: September 01, 2004, 12:41:30 PM »
Hmm.

I have been breaking this rule for ages then :-D

My C++ (AmigaOS version) layer uses a struct Process in its Threadable service class implementation rather than a Task since it is not possible to know (from the implementation point of view) which Threadable objects created by the programmer will use what other resources with their internal thread.

Every Threadable object shares resources opened by the main thread and is capable of sharing resources allocated by its internal thread with others (there is a Lockable service class that uses Semaphores for this).

The system ensures no Threadable object can outlive the thread that created it.

What I can see is that instead of Processes, I should be using Tasks. Unfortunately, IIRC Tasks can't cant call dos.library or anything which in turn woild call dos.library, which is the whole reason I used Process in the first place :-/
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: Libraries & CreateNewProc
« Reply #2 on: September 01, 2004, 07:40:25 PM »
Quote

Piru wrote:
Quote
Those DOS functions which need a process structure are protected against tasks.

Well, for example SetIoErr() is not, and various other parts of dos.library call it. So it's a bit risky to call functions from within a task, you risk trashing some memory past struct Task.


I once tried using Tasks for my needs but (for the reasons I already gave) it was a total disaster. If, and only if, your Threadable object does not use any IO (and that means interacting with any other objects that do via its internal thread) did it work. That then spawned (pun unintentional) the idea of LightThreadable and Threadable (the former using a Task in it's implementation). For something ultimately meant to make programming simpler and more flexible it was rather self defeating :-)

So in the end, I settled for a generic Threadable class that internally uses a Process.
int p; // A