0% found this document useful (0 votes)
0 views5 pages

Assignment 5

cse

Uploaded by

atharvag062
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views5 pages

Assignment 5

cse

Uploaded by

atharvag062
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

22BCE8897 SLOT = L53 - L54

ATHARAV GAIKWAD

ASSIGNMENT 5

OPERATING SYSTEMS

A. MULTITHREADING USING JAVA


PROGRAM

import java.lang.*;
import java.util.*;

// Thread A( for arithematic operations)

class A1 extends Thread


{
int i,j;
A1(int x,int y)
{
i=x;
j=y;
}
public void run()
{
System.out.println("THREAD A:: ARITHEMATIC OPERATIONS");
System.out.println("SUM "+(i+j));
System.out.println( "DIFFERENCE "+(i-j));
System.out.println(" PRODUCT "+(i*j));
System.out.println("RATIO "+(i/j));
System.out.println("POWER "+Math.pow(i,j));
System.out.println("END OF A");
}
}

// Thread B (for trignometric operations)


class B1 extends Thread
{
int i;
B1(int x)
{
i=x;
}

public void run()

{
System.out.println("THREAD B:: TRIGNOMETRIC OPERATIONS");
System.out.println("SINE OF "+i+""+Math.sin(i));
System.out.println("COSINE OF "+i+""+Math.cos(i));
System.out.println("TAN OF "+i+" "+Math.tan(i));
System.out.println("SQUARE ROOT OF "+i+" "+Math.sqrt(i));
System.out.println("END OF B");

// MAIN CLASS

class Operate
{
public static void main(String args[])
{
Scanner s=new Scanner(System.in);
System.out.println("ENTER TWO VALUES FOR ARITHEMATIC OPERATIONS");
int x=s.nextInt();
int y=s.nextInt();
System.out.println("ENTER A VALUE FOR TRIGNOMETRIC OPERATIONS");
int z=s.nextInt();
A1 a=new A1(x,y);
B1 b=new B1(z);
a.start();
b.start();

}
OUTPUT
B. MULTITHREADING USING PTHREAD
PROGRAM

#include<pthread.h>
#include<stdio.h>
#include<stdlib.h>
int sum;
void *runner(void *param);

int main(int argc,char *argv[])


{
pthread_t tid;
pthread_attr_t attr;

if(argc!=2)
{
fprintf(stderr,"usage : a.out <integer value>\n");
return -1;
}

if(atoi(argv[1])<0)
{
fprintf(stderr,"%d must be >=0\n",atoi(argv[1]));
return -1;
}

pthread_attr_init(&attr);

pthread_create(&tid,&attr,runner,argv[1]);

pthread_join(tid,NULL);
printf("argc=%d\n",argc);
printf("Sum =%d\n", sum);

void *runner(void *param)


{

int i, upper=atoi(param);
sum=0;
for(i=1;i<=upper;i++)
sum+=i;
pthread_exit(0);
}

OUTPUT

You might also like