Solved

multithread on AIX

Posted on 1998-08-17
4
402 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.NET how to use the Vertical ScrollBar 5 90
mixString challenge 36 113
bigDiff challenge 17 85
sumHeights  challenge 17 66
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

863 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now