Solved

multithread on AIX

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Powershell based monitoring system 2 127
no14 challenge 14 57
Change to event 1 74
Problem to event 3 52
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
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…
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 this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

747 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

8 Experts available now in Live!

Get 1:1 Help Now