Need Help in Programming using Threads.


 
Thread Tools Search this Thread
Top Forums Programming Need Help in Programming using Threads.
# 1  
Old 10-21-2011
Question Need Help in Programming using Threads.

Hi , i am very new to threads.. need help to build the following program.
Please if possible provide me the program.
The program should be in C language working in Linux operating systems.

Q) Execute a program using any thread library to create the number of threads specified by the user; each thread independently generates a random integer as an upper limit and then computes and prints the number of primes less than or equal to that of upper limit along with that upper limit.
# 2  
Old 10-21-2011
Try it yourself first. If you get stuck then show what you have done and we can point you in the right direction.
# 3  
Old 10-21-2011
What kind of assignment is this? There's no need for mutexes, no need to develop any communication between the threads.... This is the dumbest threads assignment I've ever seen in my life.

That said, if you can compute the number of primes, this is easy. Write a function to compute the primes, then write a function that complies with (I'm choosing pthread here) the pthread_create prototype (it'd be void *thread_fn(void *arg)) and from that function call the primes function. Then, in main call pthread_create passing thread_fn as the start_routine argument.

If you need more than that then man pthread_create. No one here is going to write the primes function for you, though. However a simple version is very easy and I'm sure you can google for it.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

From iOS programming to Linux system programming

Hello. I like Linux and C programming language. Allways wanted to understand kernel and become a Linux system programmer. And I also like Objective-C and iOS. These two programming areas have relations: 1. Linux and iOS are UNIX-like systems, POSIX compliant. 2. It is useful to know C language... (2 Replies)
Discussion started by: Rockatansky
2 Replies

2. UNIX for Dummies Questions & Answers

How does unix system administration, unix programming, unix network programming differ?

How does unix system administration, unix programming, unix network programming differ? Please help. (0 Replies)
Discussion started by: thulasidharan2k
0 Replies

3. IP Networking

socket programming using threads

Hi, 1)i wrote a program which acts lik a client gateway serving clients request and sending probe msg`s to server to chech if its active.. 2)both moduels interact when run independently my problem is that when i tr to run them as two different threads in a single program(client_gateway prog to... (4 Replies)
Discussion started by: sameer kulkarni
4 Replies

4. Programming

C Programming - Hardware Programming

Can someone help me on suggesting some ways to access the memory content in RAM directly from C/C++ source code. Please provide me any book name or any URL so that I can get an exhaustive knowledge over it. If possible please give me some tips on interacting with hardwares directly through... (3 Replies)
Discussion started by: nandumishra
3 Replies

5. Programming

Threads help

Hello! I started studying studying about POSIX Threads a few days ago... so I am a little confused and I would appreciate some help! I isolated this code... and I wonder if I could use threads in it! #include <unistd.h> #endif #include <math.h> //#include "main.h" #include <sys/time.h>... (1 Reply)
Discussion started by: smurf2
1 Replies

6. Programming

Modifying sniffex.c to include concepts of parallel programming or threads

HI For the past 1 week i have been trying to include the concepts of parallel programming or thread in the sniffex.c code. Haven't been able to.. Please suggest sm appropriate modifications to the following code: /* * sniffex.c * * Sniffer example of TCP/IP packet capture using... (1 Reply)
Discussion started by: aka.bhagvanji
1 Replies

7. UNIX for Advanced & Expert Users

Passing socket struct between kernel threads - module programming

I write kernel module with kernel threads using linux/kthread.h on 2.6.* kernel I tried to passing data between two kernel threads with data argument of kthread_run( fun, data , NAME ); but this is not work I dont know why. I tried many possibility and nothing works. So I thought that... (0 Replies)
Discussion started by: marcintom
0 Replies

8. UNIX for Dummies Questions & Answers

Carreer:Networking Programming in Unix (C programming Language)

Hello, I am trying to learn Networking Programming in C in unix enviorment. I want to know how good it is to become a network programmer. i am crazy about Network programming but i also want to opt for the best carreer options. Anybody experienced Network Programmer, please tell me is my... (5 Replies)
Discussion started by: vibhory2j
5 Replies

9. UNIX for Advanced & Expert Users

Threads and Threads Count ?

Hi all, How can I get the list of all Threads and the Total count of threads under a particular process ? Do suggest !! Awaiting for the replies !! Thanks Varun:b: (2 Replies)
Discussion started by: varungupta
2 Replies

10. Programming

c programming or unix programming!?

i would like advice on the usbject of c programming (in the middle of reading a book on C). could i benefit more if i apply that knowledge in the unix format if i were able to, or would that take the point out of learning C, basically I want to stay away from strying too far away from unix and use... (1 Reply)
Discussion started by: moxxx68
1 Replies
Login or Register to Ask a Question