Solved

multithread on AIX

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

776 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