Usenet comp.unix.osf.misc (1992-2004)
 help / color / mirror / Atom feed
* HELP: Question on DCE Threads
@ 1994-10-27 15:16 Pramod Kalapa
  1994-10-27 22:26 ` Miles_Krivoshia
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Pramod Kalapa @ 1994-10-27 15:16 UTC (permalink / raw)


I've just written a simple program using DCE threads (it is my first !).
Basically I want to create 2 threads which call a function to open a file
The thread creation call is as follows :

 if((pthread_create(&thread_hdl1, pthread_attr_default,
            (pthread_startroutine_t) open_file,
            (pthread_addr_t)NULL)) != 0)
        {
           fprintf(stderr,"%s\n","Unable to create thread1");
           exit(1);
        }

where open-file is the function to open the file. The creation routine
returns 0, which I assume is the valid value for a successful creation.
However, the thread doesn't enter the function "open_file". I've stepped
through the code with dbx and it just exits out of main. I've linked 
with the thread-safe library libc_r.a
Can someone please e-mail me as to what I might be doing wrong ?
I am using DCE 1.2 threads on AIX 3.2.5 on an IBM PowerPC. 
Thanks


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

* Re: HELP: Question on DCE Threads
  1994-10-27 15:16 HELP: Question on DCE Threads Pramod Kalapa
@ 1994-10-27 22:26 ` Miles_Krivoshia
  1994-10-28 17:24 ` Brad Daniels
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Miles_Krivoshia @ 1994-10-27 22:26 UTC (permalink / raw)


android@netcom.com (Pramod Kalapa) writes:
> where open-file is the function to open the file. The creation routine
> returns 0, which I assume is the valid value for a successful creation.
> However, the thread doesn't enter the function "open_file". I've stepped
> through the code with dbx and it just exits out of main. I've linked 
> with the thread-safe library libc_r.a
> Can someone please e-mail me as to what I might be doing wrong ?

Yes, while the new thread starts, them main thread keeps running, and
when main exits, the whole process may end (implementation dependent).
Try calling pthread_join() in main.

-Miles



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

* Re: HELP: Question on DCE Threads
  1994-10-27 15:16 HELP: Question on DCE Threads Pramod Kalapa
  1994-10-27 22:26 ` Miles_Krivoshia
@ 1994-10-28 17:24 ` Brad Daniels
  1994-10-31 14:37 ` Paul Roberts
  1994-11-09 13:26 ` Rich Salz
  3 siblings, 0 replies; 5+ messages in thread
From: Brad Daniels @ 1994-10-28 17:24 UTC (permalink / raw)


In article <androidCyC7rD.MKv@netcom.com>,
Pramod Kalapa <android@netcom.com> wrote:
...
> The creation routine
>returns 0, which I assume is the valid value for a successful creation.
>However, the thread doesn't enter the function "open_file". I've stepped
>through the code with dbx and it just exits out of main. I've linked 
>with the thread-safe library libc_r.a
>Can someone please e-mail me as to what I might be doing wrong ?
>I am using DCE 1.2 threads on AIX 3.2.5 on an IBM PowerPC. 

It sounds like you need to either use pthread_join to join with the thread
or do something else to make sure you don't exit before the thread does its
work.

- Brad
------------------------------------------------------------------
+ Brad Daniels           | "For all men would be cowards         +
+ Biles and Associates   |  if they durst."                      +
+ My views, not B&A's    |      - John Wilmot, Earl of Rochester +
------------------------------------------------------------------


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

* Re: HELP: Question on DCE Threads
  1994-10-27 15:16 HELP: Question on DCE Threads Pramod Kalapa
  1994-10-27 22:26 ` Miles_Krivoshia
  1994-10-28 17:24 ` Brad Daniels
@ 1994-10-31 14:37 ` Paul Roberts
  1994-11-09 13:26 ` Rich Salz
  3 siblings, 0 replies; 5+ messages in thread
From: Paul Roberts @ 1994-10-31 14:37 UTC (permalink / raw)


Pramod Kalapa (android@netcom.com) wrote:
: I've just written a simple program using DCE threads (it is my first !).
: Basically I want to create 2 threads which call a function to open a file
: The thread creation call is as follows :

:  if((pthread_create(&thread_hdl1, pthread_attr_default,
:             (pthread_startroutine_t) open_file,
:             (pthread_addr_t)NULL)) != 0)
:         {
:            fprintf(stderr,"%s\n","Unable to create thread1");
:            exit(1);
:         }

: where open-file is the function to open the file. The creation routine
: returns 0, which I assume is the valid value for a successful creation.
: However, the thread doesn't enter the function "open_file". I've stepped
: through the code with dbx and it just exits out of main. I've linked 
: with the thread-safe library libc_r.a
: Can someone please e-mail me as to what I might be doing wrong ?
: I am using DCE 1.2 threads on AIX 3.2.5 on an IBM PowerPC. 
: Thanks

dbx in AIX is thread-safe and thread-aware. If you do a stop in 
open_file command and then continue within dbx, you should see it
enter your function. The AIX dbx also has a "threads" subcommand
where you can observe the threads during execution.

--
Paul Roberts                                e-mail: probert@uhc.com
United HealthCare Corporation, MN06-6130    phone:  612-945-6378
P.O. Box 1459, Minneapolis, MN 55440	    fax:    612-945-6502


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

* Re: HELP: Question on DCE Threads
  1994-10-27 15:16 HELP: Question on DCE Threads Pramod Kalapa
                   ` (2 preceding siblings ...)
  1994-10-31 14:37 ` Paul Roberts
@ 1994-11-09 13:26 ` Rich Salz
  3 siblings, 0 replies; 5+ messages in thread
From: Rich Salz @ 1994-11-09 13:26 UTC (permalink / raw)


In <androidCyC7rD.MKv@netcom.com> android@netcom.com (Pramod Kalapa) writes:
> if((pthread_create(&thread_hdl1, pthread_attr_default,
>            (pthread_startroutine_t) open_file,
>            (pthread_addr_t)NULL)) != 0)

>However, the thread doesn't enter the function "open_file". I've stepped
>through the code with dbx and it just exits out of main.

Just to clarify, the thread that called pthread_create doesn't enter
open_file.  Instead a new "flow of execution" starts.  If your
main is doing
	pthread_create
	pthread_create
	exit
Then what is probably happening is that the three threads are running
just before exit, but then they're all shut down by the process exit.
You probably want to put
	pthread_join(&thread_hdl1);
	pthread_join(&thread_hdl2);
before your call to exit.  This will make sure that your process doesn't
go away until all the threads are finished.

As a side note, very few debuggers are aware of threads.  I don't know
about AIX's dbx (this is also an inside joke :-).  You might find it
easier to do something like
	 if((pthread_create(&thread_hdl1, pthread_attr_default,
	            open_file, "#1")) != 0)
	 if((pthread_create(&thread_hdl2, pthread_attr_default,
	            open_file, "#2")) != 0)
And write open_file as
	void *open_file(void *arg) {
	    if (debugging && arg != NULL) {
		fprintf(stderr, "open_file %s started\n", (char *)arg);
		fflush(stderr);
	    }
	    ... real body of the thread ...
	}


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

end of thread, other threads:[~1994-11-09 13:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1994-10-27 15:16 HELP: Question on DCE Threads Pramod Kalapa
1994-10-27 22:26 ` Miles_Krivoshia
1994-10-28 17:24 ` Brad Daniels
1994-10-31 14:37 ` Paul Roberts
1994-11-09 13:26 ` Rich Salz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox