Index: Sl. No Experiment Name Page No
Index: Sl. No Experiment Name Page No
2 Create ‘n’ number of child threads. Each thread prints the message 2
“I’m in thread number …” and sleeps for 50 ms and then quits.
The main thread waits for complete execution of all the child
threads and then quits. Compile and execute in Linux.
3 Implement the multi-thread application satisfying the following: 3
a) Two child threads are created with normal priority.
b) Thread 1 receives and prints its priority and sleeps for 50ms
and then quits.
c) Thread 2 prints the priority of the thread 1 and rises its priority
to above normal and retrieves the new priority of thread 1, prints it
and then quits.
d) The main thread waits for the child thread to complete its job
and quits.
4 Write ALP to find the square of a number (1 to 10) using look-up 7
table
Experiment No. 1
Program:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
if (pid < 0) {
perror("Fork failed");
return 1;
} else if (pid == 0) { // Child process
printf("Child Process: PID = %d, Parent PID = %d\n", getpid(), getppid());
childFunction(1); // Call child function with a switch statement
exit(0); // Exit child process
} else { // Parent process
printf("Parent Process: PID = %d, Child PID = %d\n", getpid(), pid);
wait(NULL); // Wait for child to complete
}
return 0
Output:
Parent Process: PID = 12345, Child PID = 12346
Child Process: PID = 12346, Parent PID = 12345
Child process executing task 1...
M.Tech in VLSI Design & Embedded System
Dept. of ECE VTU CPGS Kalaburagi Page 1
ADVANCED EMBEDDED SYSTEMS LAB
Experiment No.2
Create ‘n’ number of child threads. Each thread prints the message “I’m in
thread number …” and sleeps for 50 ms and then quits. The main thread
waits for complete execution of all the child threads and then quits. Compile
and execute in Linux.
Program:
#include<stdio.h>
#include<pthread.h>
pthread_t tid[5];
int main(){
int n=5;
int ret;
int i;
for(i=0;i<5;i++){
// Create thread using POSIX standards
ret = pthread_create(&tid[i], NULL, &thread_print, (void *) i);
}
Output:
I'M IN THREAD NUMBER 0
I'M IN THREAD NUMBER 1
I'M IN THREAD NUMBER 2
I'M IN THREAD NUMBER 3
I'M IN THREAD NUMBER 4
Experiment No.3
Program:
#include<stdio.h>
#include<pthread.h>
#include<sys/types.h>
#include<unistd.h>
#include<stdlib.h>
#include<semaphore.h>
#include<string.h>
#include<stdlib.h>
#include<fcntl.h>
sem_t empty,full,mutex;
char child_buf[512];
//child thread
int j=1,k=0;
while(j)
{
k++;
/*
*/
int main()
{
pthread_t pid1,pid2;
int item=1,i=0;
char *parent_msg;
int fi = mkfifo(myfifo, 0666); // Create fifo
pthread_create(&pid1,NULL,Child_Thread,NULL);
printf("\n\nthread created\n");
while(item)
{
i=i++;
int k = rand(); // to generate random number of parent msg's
if((k % 10) < 3){
item = 0;
parent_msg = "WM_QUIT";
}
else
{ parent_msg = "Hi I am parent";
}
sem_post(&mutex);
sem_post(&full);
sleep(1);
}
pthread_join(pid1,NULL);
//printf("xxxxxxxxxxxxxx\n");
return 0;
}
Output:
Thread created
Parent message: Hi, I am the parent
Inside parent (PRODUCER) - Produced: Hi, I am the parent [1]
Experiment No.04
Write ALP to find the square of a number (1 to 10) using look-up table
Program:
Output:
R3=24(36 in hexadecimal )
Experiment No.05
a)ascending order
Program:
Output:
Memory register 0x40000000:11 11 11 11 22 22 22 22 33 33 33 33 44 44 44 44 00 00 00 00
b)descending order
Program:
Output:
Experiment No.6
Write an ALP to count the number of ones and zeros in two consecutive
memory locations.
Program:
AREA ONEZERO,CODE,READONLY
ENTRY
MOV r2,#0;
MOV r3,#0;
MOV r7,#2
LDR r6,=VALUE
LOOP MOV r1,#32
LDR r0,[r6],#4
LOOP0 MOVS r0,R0,ROR#1
BHI ONES
ZEROS ADD r3,r3,#1
B LOOP1
ONES ADD r2,r2,#1
LOOP1 SUBS r1,r1,#1
BNE LOOP0
SUBS r7,r7,#1
CMP r7,#0
BNE LOOP
BACK B BACK
VALUE DCD 0X11111111,0XAA55AA55
END
Output:
Experiment No.7
Interface a simple Switch and display its status through Relay, Buzzer and
LED.
Program:
#include <LPC213x.h>
void delay()
{
int i,j:
for(i=0;i<1000;i++)
for(j=0,j<100;j++);
}
int main (void)
{
IO0DIR = 0X01;
while (1)
{
if ((IO0PIN & 91<<2))==0)
{
IO0SET |= (1<<0);
}
else
{
IO0CLR |=(1<<0);
}
}