wrong example in thr_create(3T) man page

wrong example in thr_create(3T) man page

Post by Andreas Sinderman » Tue, 06 May 1997 04:00:00



Hello,

in the Solaris 2.5.1 man page about thr_create a wrong example is
presented. During compilation I get the following errors:

22:57:47 sun18 ~ 137 >cc testfile.c -lthread -lpthread
"testfile.c", line 19: warning: improper pointer/integer combination: arg #4
"testfile.c", line 33: syntax error before or at: *
"testfile.c", line 33: warning: parameter mismatch: 1 declared, 0 defined
cc: acomp failed for testfile.c

The problem is that '10' is supposed to be given as the argument
to the sleeping function but it's an integer, not a void.

Any idea how to transfer the argument correctly?

TIA,
Andreas

/* cc thisfile.c -lthread -lpthread */
#define _REENTRANT    /* basic 3-lines for threads */
#include <pthread.h>
#include <thread.h>

#define NUM_THREADS 5
#define SLEEP_TIME 10

void *sleeping(void *);   /* thread routine */
void test_argv();         /* optional */
int i;
thread_t tid[NUM_THREADS];      /* array of thread IDs */

main( int argc, char *argv[] ) {
  test_argv(argv[1]);

  switch (*argv[1])  {
    case '0':  /* POSIX */
      for ( i = 0; i < NUM_THREADS; i++)
        pthread_create(&tid[i], NULL, sleeping, SLEEP_TIME);
      for ( i = 0; i < NUM_THREADS; i++)
        pthread_join(tid[i], NULL);
      break;

    case '1':  /* Solaris */
      for ( i = 0; i < NUM_THREADS; i++)
        thr_create(NULL,0,sleeping,NULL,0,&tid[i]);
      while (thr_join(NULL, NULL, NULL) == 0);
      break;
  }  /* switch */
  printf("main() reporting that all %d threads have terminated\n", i);

Quote:}  /* main */

void *sleeping(int sleep_time *)     {
  printf("thread %d sleeping %d seconds ...\n", thr_self(), SLEEP_TIME);
  sleep(sleep_time);
  printf("\nthread %d awakening\n", thr_self());

Quote:}

void test_argv(char argv1[])   {    /* optional */
  if (argv1 == NULL)  {
    printf("use 0 as arg1 to use thr_create();\n \
            or use 1 as arg1 for use pthread_create()\n");
    exit(NULL);
  }
Quote:}

 
 
 

wrong example in thr_create(3T) man page

Post by Andy Tucke » Tue, 06 May 1997 04:00:00



> Hello,

> in the Solaris 2.5.1 man page about thr_create a wrong example is
> presented. During compilation I get the following errors:

> 22:57:47 sun18 ~ 137 >cc testfile.c -lthread -lpthread
> "testfile.c", line 19: warning: improper pointer/integer combination: arg #4
> "testfile.c", line 33: syntax error before or at: *
> "testfile.c", line 33: warning: parameter mismatch: 1 declared, 0 defined
> cc: acomp failed for testfile.c

> The problem is that '10' is supposed to be given as the argument
> to the sleeping function but it's an integer, not a void.

> Any idea how to transfer the argument correctly?

> TIA,
> Andreas

[broken example deleted]

Oops.  Here's a better version, that actually compiles and runs.

/* cc thisfile.c -lthread -lpthread */
#define _REENTRANT    /* basic 3-lines for threads */
#include <pthread.h>
#include <thread.h>

#define NUM_THREADS 5
#define SLEEP_TIME 10

void *sleeping(void *);   /* thread routine */
int i;
thread_t tid[NUM_THREADS];      /* array of thread IDs */

int
main(int argc, char *argv[])
{
        if (argc == 1)  {
                printf("use 0 as arg1 to use pthread_create();\n"
                       "or use 1 as arg1 to use thr_create()\n");
                return (1);
        }

        switch (*argv[1])  {
        case '0':  /* POSIX */
                for ( i = 0; i < NUM_THREADS; i++)
                        pthread_create(&tid[i], NULL, sleeping,
                            (void *)SLEEP_TIME);
                for ( i = 0; i < NUM_THREADS; i++)
                        pthread_join(tid[i], NULL);
                break;

        case '1':  /* Solaris */
                for ( i = 0; i < NUM_THREADS; i++)
                        thr_create(NULL, 0, sleeping, (void
*)SLEEP_TIME, 0,
                            &tid[i]);
                while (thr_join(NULL, NULL, NULL) == 0)
                        ;
                break;
        }  /* switch */
        printf("main() reporting that all %d threads have terminated\n",
i);
        return (0);

Quote:}  /* main */

void *
sleeping(void *arg)
{
        int sleep_time = (int)arg;
        printf("thread %d sleeping %d seconds ...\n", thr_self(),
sleep_time);
        sleep(sleep_time);
        printf("\nthread %d awakening\n", thr_self());
        return (NULL);

Quote:}

--
Andy Tucker

Solaris Clustering
I speak only for myself, not SunSoft or Sun Microsystems.

 
 
 

1. Problem in SGML source for thr_setprio(3t) man page

I don't know any better way to bring this to people's attention, so I'm
posting here.  Others can feel free to confirm this problem.

On my installations (Solaris 7 3/99 MU3), there appears to be a problem
with the thr_setprio(3t) SGML source in
/usr/share/man/sman3t/thr_setprio.3t.  This file provides a link to
itself rather than providing content.  This results in the inability to
view this man page.

The contents of the thr_setprio(3t) man page are in the thr_getprio(3t)
page.  Therefore, the thr_setprio(3t) page should reference
thr_getprio(3t).  Here is the correct SGML source:

--
<!DOCTYPE REFENTRY PUBLIC "-//Sun Microsystems//DTD DocBook V3.0-Based
SolBook Subset V2.0//EN" [
<!-- SHADOW_PAGE -->
<!ENTITY thr-setprio-3t SYSTEM "./thr_getprio.3t">
]>
&thr-setprio-3t;
--

This has actually been bothering me for some time, but it's about time
I spoke up about it.

-MM

2. Automatic merge of code

3. Standard man pages to "Catted" man pages!

4. Installing a package multiple times on a machine

5. Call for examples for POSIX man pages

6. DIP and serial line speeds > 38.4K

7. HELP: mknod command....sparc2 can't see external tape...no example on man page

8. Automated mail printing RH5.1 via shared printer on NT/WIN98

9. Question about queueing example in man page for pf.conf (current)

10. More page outs than page ins?

11. How to format BSD man pages (groff man) using "classical" troff man?

12. program or man page wrong for getent ethers NAME ?

13. man-pages won't be formatted with groff, what's wrong?