Solved

multithread on AIX

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Windows Drag & Drop Location 2 108
mixString challenge 36 132
substring method in java 1 130
countEvens challenge 2 112
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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…

830 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