Hi All, I am trying some experiments with pthread scheduling policies. I have a couple of apps and within all these apps, I set the thread policy to SCHED_RR and I set the priority to MAX - 1. Now, I see that the CPU utilization as reported by top for one process goes to about 100%. However, the other apps don't have the same behavior. **Question:** Doesn't setting SCHED_RR as the scheduling policy ensure that all threads get equal quanta of CPU cycles? If yes, why is top reporting these numbers as high for one process? **More info:** 1. I'm …

Member Avatar
Member Avatar
+0 forum 2

can anyone help me in making a c program for displaying the grades(A(>60),B(45>b<60),C(30>c<45),F(fail)) of students in the form of histograms and for each grade calculation and histogram we need to use pthreads!!! so that it satisfies parallel processing!!

Member Avatar
Member Avatar
+0 forum 1

In a past prac. exam for an algorithm course I'm doing is the challenge below, and their are no solutions but it seems like a really interesting one to solve. Can someone please help and point me in the right direction, I would like to try this on my own, but please give some assistance. I need to write a multithreaded program (using pthreads, code must run on linux, i'm using ubuntu maverick) to simulate a shuttle that operates on a circuit, stopping at the stadium, and the city center only. 1) The shuttle waits until the occupants signal for …

Member Avatar
Member Avatar
+0 forum 14

The assignment is to implement the Banker's Algorithm using pthreads and mutex locks. We implemented the Banker's Algorithm and it works fine. When we began implementing the pthreads and mutex locks we ran into problems. We know that each process is a thread, and that the mutex lock is acquired once it is inside of the Banker's Algorithm function and it is released once you leave the function. We are just confused about how the threads come into play.

Member Avatar
Member Avatar
+0 forum 1

Hi people. I wonder how I can free the pthreads' allocated memory? #include <pthread.h> #include <stdio.h> #include <stdlib.h> #define NUM_OF_THREADS 10 void* print_thread_id(void* tid) { printf("Greetings from thread %d\n", (*(int*)tid)); pthread_exit(NULL); } int main(int argc, char* argv[]) { pthread_t threads[NUM_OF_THREADS]; int status, i; int* n_thread; for(i = 0; i < NUM_OF_THREADS; i++) { if((n_thread = malloc(sizeof(int))) == NULL) return EXIT_FAILURE; *n_thread = i; printf("Main here. Creating thread %d\n", i); if((status = pthread_create(&threads[i], NULL, print_thread_id, n_thread)) != 0) { printf("ERROR. Thread error code: %d\n", status); exit(EXIT_FAILURE); } free(n_thread); } return EXIT_SUCCESS; } ==11701== LEAK SUMMARY: ==11701== definitely lost: 0 bytes in …

Member Avatar
Member Avatar
+0 forum 1

My basic problem is that I'm having a hard time implementing a Pthread that consists of a round robin dequeuing 4 arrays consisting of ints. Followed by a Pthread that creates random numbers with which to enqueue them with. I've written most of the code for the queue itself and I've read up a lot on Pthreads, but I haven't found anything that explains it clearly. Here is my code for reference. [CODE=c]#include <stdio.h> #include <ctype.h> #include <stdlib.h> #include <string.h> #include <math.h> #include <pthread.h> #define MaxQueueSize 10 #define FALSE 0 #define TRUE 1 typedef struct { int content[MaxQueueSize]; int head; …

Member Avatar
+0 forum 0

Hi I'm trying to create a program that gathers data from some ADC connected and do some averaging on the data. It's build up around classes containing systeminterface and sensors making a datamodel. The program is pretty big, but has worked intil implemention of pthreads I wanted to create a thread maintaining the sensors an averaging a couple of samples. I ran into the problem about callback, and classes, googled and found a workaround :) But i'm getting this linker error and I cannot figure out where. [CODE] h2SystemInterface.o: In function `H2SystemInterface::H2SystemInterface()': h2SystemInterface.cpp:(.text+0x665): undefined reference to `H2SystemInterface::threadCaller(void*)' h2SystemInterface.cpp:(.text+0x66c): undefined reference …

Member Avatar
+0 forum 0

All I have to do is take an array of n integers and run p threads to sort equally divided p blocks of the same and finally merge them. There is occuring some problem in my code. If I run the threads one by one, by using pthread_join's before next thread, its working all good. This is some trivial error but now I cant give it more. Please help. #include <stdio.h> #include <stdlib.h> #include <pthread.h> #include <time.h> void *func_sort(void *ptr); typedef struct{ int *arr; int n, p, start; }arg; main() { pthread_t* th; int n, p, *arr, i, j, *fin, …

Member Avatar
Member Avatar
+0 forum 1

I am using a) Linux b) Pthreads I want to write a program, with two pthreads, to cater for two queues of people. People arrive at each queue at a random interval of 1 - 10 seconds. Each time a person arrives, print out the number of people in each queue to the screen. Apparently sleep() pauses the whole program, how can a pause one particular thread??

Member Avatar
Member Avatar
+0 forum 4

hello im new to linux programming and i am experiencing a bit of diffuclty with pthreads...basically the pthread_create() function in my code below i tend to pass an integer variable as the argument for my runner() function but i get a warning and an error..i have tried several ways of passing this argument but im not very good with pointers...a bit of help in my code would be appreciated.. [CODE] #include<pthread.h> #include<stdio.h> #include<sys/types.h> #include<sys/ipc.h> #include<semaphore.h> #include<unistd.h> pthread_t t1,t2; pthread_attr_t tattr; int counter; sem_t mutex; void runner(void *arg) { printf("Thread received %i",*arg); int i=0; for(i=0;i<5;i++) { sem_wait(&mutex); printf("Thread %i says %i",*((int …

Member Avatar
Member Avatar
+0 forum 4

I'm working on a project that utilizes producers and consumers for an operating systems class. Each producer and each consumer will be its own thread. The producers will generate records that will be stored in a global buffer, in which the consumer will then access to use the data. I am having a hard time figuring out how to use actual pthreads. My original plan was to create a Producer class and a Consumer class and simulate the threads, but we are told now not to do so. Is there a c++ class for this? Also, for the buffer, I …

Member Avatar
Member Avatar
+0 forum 10

Can anyone help me improve my source code below? I tried fixing it but apparently, there's not much success. [CODE] #define NUM_THREADS1 1 void *go_to_website2(void *program); void *go_to_website1(void *program) { char* str[3]; str[0] = (char *)program; str[1] = "http://www.google.com"; //supposedly 2nd website to go to str[2] = '\0'; char* new_prog = "firefox"; pthread_t th; int rc2; rc2 = pthread_create(&th, NULL, go_to_website2, (void *)new_prog); //2nd thread created pthread_join(th, NULL); //wait for the second thread th to be finished execvp(str[0], str); //go to 2nd website (google.com), unsuccessfully opened } void *go_to_website2(void *program) { char* str2[3]; str2[0] = (char *)program; str2[1] = "http://www.yahoo.com"; …

Member Avatar
Member Avatar
+0 forum 9

The End.