Solved

multithread on AIX

Posted on 1998-08-17
4
438 Views
Last Modified: 2013-12-26
I'd like to have an example of using multithread on AIX 4.  The example only need to create another thread and run it.

Please also include the make file.
0
Comment
Question by:faster
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 2

Expert Comment

by:JYoungman
ID: 1292910
Doesn't AIX support POSIX threads?

0
 
LVL 2

Accepted Solution

by:
seedy earned 100 total points
ID: 1292911
The following code segment starts two similar threads, waits for their completion and then terminates.  Cut the code segment and paste in a file, say 't.c'.  Compile using the following command
     cc_r t.c -o t -lpthreads

-- code segment start --
#include <pthread.h>
#include <stdio.h>

#define COUNT   (INT_MAX/10)

void *FirstThread(void *v)
{
        int i = 0;

        printf("Thread one started\n");
        while ( i < COUNT )
                i++;
        printf("Thread one done - %d\n",i);
        pthread_exit(&i);
}
void *SecondThread(void *v)
{
        int i = 0;
        printf("Thread two started\n");
        while ( i < COUNT )
                i++;
        printf("Thread two done - %d\n",i);
        pthread_exit(&i);
}
main()
{
        pthread_t t1, t2;
        pthread_attr_t attr;
        int i;

        if ( pthread_attr_init(&attr) )
                perror("attr init");

/* Create a attached thread, so that we can wait for its completion */
        if (  pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_UNDETACHED) )
                perror("set detach");

        if ( pthread_create(&t1, &attr, FirstThread, NULL) )
                perror("thread create failed");
        if ( pthread_create(&t2, &attr, SecondThread, NULL) )
                perror("thread create failed");

/* wait for threads to complete */
        pthread_join(t1, NULL);
        printf("Thread one completed\n");
        pthread_join(t2, NULL);
        printf("Thread two completed\n");
}
-- code segment end --
0
 
LVL 7

Author Comment

by:faster
ID: 1292912
Thanks a lot.  One more question: what is the difference between cc and cc_r?
0
 
LVL 2

Expert Comment

by:seedy
ID: 1292913
I *think* cc_r links with thread safe libraries and generates re-entrant code.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Host to IP 7 84
unable to delete all specified values regedit 38 869
Best tools for Backup and restore of Wordpress site 6 58
sumNumber challenge 16 145
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
In this post we will learn different types of Android Layout and some basics of an Android App.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question