9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] Threadcreate() failure value?
@ 2005-11-30 16:03 ISHWAR RATTAN
  2005-11-30 18:31 ` Russ Cox
  0 siblings, 1 reply; 9+ messages in thread
From: ISHWAR RATTAN @ 2005-11-30 16:03 UTC (permalink / raw)
  To: 9fans


The man page does not mention what is the value returned
by threadcreate() and proccreate() on failure? Can one safely
assume that it is -1?

-ishwar



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [9fans] Threadcreate() failure value?
  2005-11-30 16:03 [9fans] Threadcreate() failure value? ISHWAR RATTAN
@ 2005-11-30 18:31 ` Russ Cox
  2005-11-30 19:02   ` ISHWAR RATTAN
  0 siblings, 1 reply; 9+ messages in thread
From: Russ Cox @ 2005-11-30 18:31 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

> The man page does not mention what is the value returned
> by threadcreate() and proccreate() on failure? Can one safely
> assume that it is -1?

thread(2):

        Thread library functions do not return on failure;
        if errors occur, the entire program is aborted.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [9fans] Threadcreate() failure value?
  2005-11-30 18:31 ` Russ Cox
@ 2005-11-30 19:02   ` ISHWAR RATTAN
  2005-11-30 19:16     ` Russ Cox
  0 siblings, 1 reply; 9+ messages in thread
From: ISHWAR RATTAN @ 2005-11-30 19:02 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs



On Wed, 30 Nov 2005, Russ Cox wrote:
> thread(2):
>
>        Thread library functions do not return on failure;
>        if errors occur, the entire program is aborted.

Interesting. If threads are being created by a min thread on the
fly to handle some task, it means all threads (including main thread)
disappear?? What if there is a need for active threads to complete
the assigned tasks?

-ishwar


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [9fans] Threadcreate() failure value?
  2005-11-30 19:02   ` ISHWAR RATTAN
@ 2005-11-30 19:16     ` Russ Cox
  2005-11-30 19:59       ` Ronald G Minnich
  0 siblings, 1 reply; 9+ messages in thread
From: Russ Cox @ 2005-11-30 19:16 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

> On Wed, 30 Nov 2005, Russ Cox wrote:
> > thread(2):
> >
> >        Thread library functions do not return on failure;
> >        if errors occur, the entire program is aborted.
>
> Interesting. If threads are being created by a main thread on the
> fly to handle some task, it means all threads (including main thread)
> disappear??

The only way these can fail is if you run out of memory
or you run out of processes.

> What if there is a need for active threads to complete
> the assigned tasks?

Then you should fix the memory or process leaks.

Russ


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [9fans] Threadcreate() failure value?
  2005-11-30 19:16     ` Russ Cox
@ 2005-11-30 19:59       ` Ronald G Minnich
  2005-11-30 20:39         ` Russ Cox
  0 siblings, 1 reply; 9+ messages in thread
From: Ronald G Minnich @ 2005-11-30 19:59 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

Russ Cox wrote:

>>What if there is a need for active threads to complete
>>the assigned tasks?
> 
> 
> Then you should fix the memory or process leaks.
> 
> Russ


what if your create failed due to some other process having the process 
leak, and you'd like your process, which has done nothing wrong, to get 
out of the mess cleanly?

ron


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [9fans] Threadcreate() failure value?
  2005-11-30 19:59       ` Ronald G Minnich
@ 2005-11-30 20:39         ` Russ Cox
  2005-11-30 20:43           ` Ronald G Minnich
  2005-11-30 20:58           ` Martin Harriss
  0 siblings, 2 replies; 9+ messages in thread
From: Russ Cox @ 2005-11-30 20:39 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

> what if your create failed due to some other process having the process
> leak, and you'd like your process, which has done nothing wrong, to get
> out of the mess cleanly?

Then you will need to change the thread library and then
edit all the programs that use it to check the return values
on threadcreate and proccreate.

Russ


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [9fans] Threadcreate() failure value?
  2005-11-30 20:39         ` Russ Cox
@ 2005-11-30 20:43           ` Ronald G Minnich
  2005-11-30 20:50             ` Russ Cox
  2005-11-30 20:58           ` Martin Harriss
  1 sibling, 1 reply; 9+ messages in thread
From: Ronald G Minnich @ 2005-11-30 20:43 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

Russ Cox wrote:
>>what if your create failed due to some other process having the process
>>leak, and you'd like your process, which has done nothing wrong, to get
>>out of the mess cleanly?
> 
> 
> Then you will need to change the thread library and then
> edit all the programs that use it to check the return values
> on threadcreate and proccreate.

or ....

provide versions of the functions that return on error, for those cases 
where they are needed. And then have the "normal" function call this 
function, and on failure, act as it acts now (i.e. exit)?

I realize that just blowing the process away on this type of failure is 
a very reasonable thing to do, but in a very few cases here, we need to 
recover and stumble along in the case of such failure, and try to at 
least get to a sane state before dying.

ron


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [9fans] Threadcreate() failure value?
  2005-11-30 20:43           ` Ronald G Minnich
@ 2005-11-30 20:50             ` Russ Cox
  0 siblings, 0 replies; 9+ messages in thread
From: Russ Cox @ 2005-11-30 20:50 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

> I realize that just blowing the process away on this type of failure is
> a very reasonable thing to do, but in a very few cases here, we need to
> recover and stumble along in the case of such failure, and try to at
> least get to a sane state before dying.

If you really have a need for this, then let me know and I'll do something.
The most likely solution is to have a user-supplied error function
like the regular expression and draw libraries have.

But I'm not going to spend time on this for its own sake.

Russ


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [9fans] Threadcreate() failure value?
  2005-11-30 20:39         ` Russ Cox
  2005-11-30 20:43           ` Ronald G Minnich
@ 2005-11-30 20:58           ` Martin Harriss
  1 sibling, 0 replies; 9+ messages in thread
From: Martin Harriss @ 2005-11-30 20:58 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

>>what if your create failed due to some other process having the process
>>leak, and you'd like your process, which has done nothing wrong, to get
>>out of the mess cleanly?

One of the problems is that the program that finds itself unable to 
proceed for lack of resources may not be able to recover because it 
needs resources to run the recovery mechanism.

This was dicussed a long time ago wrt memory allocation for Modula 3. 
See, for example:

http://www.elegosoft.com/pm3/intro/questions/new.html

(I'm sure that somewhere I've seen a more basic description of why 
handling out-of-memory conditions is diffucult, but I can't find it 
right now.)

I'd be the first to admit that this is a somewhat different case because 
M3 relies heavily on dynamic memory allocation and garbage collection, 
but I think that in general terms the issues are the same.

Martin


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2005-11-30 20:58 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-11-30 16:03 [9fans] Threadcreate() failure value? ISHWAR RATTAN
2005-11-30 18:31 ` Russ Cox
2005-11-30 19:02   ` ISHWAR RATTAN
2005-11-30 19:16     ` Russ Cox
2005-11-30 19:59       ` Ronald G Minnich
2005-11-30 20:39         ` Russ Cox
2005-11-30 20:43           ` Ronald G Minnich
2005-11-30 20:50             ` Russ Cox
2005-11-30 20:58           ` Martin Harriss

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).