HP3000-L Archives

June 2000, Week 4

HP3000-L@RAVEN.UTC.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Doug Becker <[log in to unmask]>
Reply To:
Doug Becker <[log in to unmask]>
Date:
Tue, 27 Jun 2000 09:31:07 -0700
Content-Type:
text/plain
Parts/Attachments:
text/plain (146 lines)
Suppose you are a third party software vendor realizing that you cannot effectively use
multi-threaded sockets using CREATEPROCESS because the task blocks for the socket are not
copied into the CREATEd environment.

You can use fork or you may consider using pthread.

Pthread has several advantages over fork. For one thing it is clear where you are in the
code at any given time--and you are running with a separate processor stack, meaning that
two or more sets of instructions in your program may be "concurrent".

Now, suppose that you need to issue a **critical** message from a subroutine activated by pthread
to the person using this mult-threaded program at their PC connected to the HP 3000.

If that person has NS/3000 and is using a terminal emulator recognized by NS as being a candidate
for Native Mode Terminal I/O, everything will work fine.

If it turns out that you are on a dumb terminal, or the console, or on a dial-up modem, or
you don't have NS/3000, the **critical** message will never be received.

Here is the C code used to test multi-threading:

#define _POSIX_SOURCE
#define _POSIX_THREADS
#define _REENTRANT

#include <pthread.h>
#include <stdio.h>
#include <errno.h>
#include <unistd.h>

pthread_thread_t thread1, thread2;
pthread_attr_t attr;
void thread_funct1();
void thread_funct2();
pthread_addr_t arg1, arg2;

int main()
{
  int pstat;
  int pstat2;
  pstat=0;
  pstat2=0;

  printf("starting threads\n");
  pstat = pthread_create( &thread1, pthread_attr_default,
                        (pthread_startroutine_t) thread_funct1,
                         &arg1);
  if (pstat != 0)
     perror("pthread create 1 failed : ");
  else
  {
    printf("pstat = 0; creating thread2\n");
    pstat2 = pthread_create( &thread2, pthread_attr_default,
                          (pthread_startroutine_t) thread_funct2,
                           &arg2);
    if (pstat2 != 0)
       perror("pthread create 2 failed : ");
    else
    {
      printf("waiting on thread\n");
      pstat = pthread_join(thread1, (void **) arg1);
      pstat2 = pthread_join(thread2, (void **) arg2);
    }
  }
}

void thread_funct1()
{

  int k;
  printf("Entering thread_funct1()\n");
  for (k=0;k<6;k++)
  {
    printf("I'm thread one!!!\n");
    sleep(2);
  }
  pthread_exit(arg1);
}

void thread_funct2()
{

  int i;
  printf("Entering thread_funct2()\n");
  printf("I'm the looping thread\n");
  for (i=0;i<5;i++)
  {
    printf("thread 2 is sleeping zzz...zzz...\n");
    sleep(2);
  }
  pthread_exit(arg2);
}

---------------------------------------------------
Running the program should look like this:

:./runthread
starting threads
pstat = 0; creating thread2
Entering thread_funct1()

I'm thread one!!!

waiting on thread
Entering thread_funct2()

I'm the looping thread

thread 2 is sleeping zzz...zzz...

I'm thread one!!!

thread 2 is sleeping zzz...zzz...

I'm thread one!!!

thread 2 is sleeping zzz...zzz...

I'm thread one!!!

thread 2 is sleeping zzz...zzz...

I'm thread one!!!

thread 2 is sleeping zzz...zzz...

I'm thread one!!!

:
--------------------------------------
If you don't have NS/3000, the only thing you will see is:

starting threads

--------------------------------------
The rest of SYSLIST completely disappears.

What is interesting is the approach that the HP development engineers are taking:

They are seriously discussing removing pthread from FOS and moving it to NS.

That is certainly one way to solve the problem!

It may be well to consider petitioning HP through Interex to leave the POSIX pthread function in FOS and moving the resolution
of the problem from NS to FOS.

ATOM RSS1 RSS2