954,498 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Homework problem

somebody help me please!
Write the following C\C++ program:
Program starts two threads (from now onwards A and B).

Main program generates number N from range 5000 and 10000.

Number N is passed to thread A.

Threads A generates N random numbers from the range [1, 100].

Generated numbers are passed to thread B.

Thread B writes these numbers to a file. The user of the program is prompted in the main thread for the names of the file (path) number are to be written to. The name is passed to the thread B.

Each thread returns count of processed numbers to the main program. The massage showing both counts should be printed at last.

To control run of threads events mechanism should be used.

Identification numbers of the process and threads should be printed out.

The zipped project needs to be written in Eclipse-Galileo environment.

zzjason
Newbie Poster
3 posts since Jan 2010
Reputation Points: 6
Solved Threads: 0
 

Could you show us what you have so far...

gerard4143
Nearly a Posting Maven
2,272 posts since Jan 2008
Reputation Points: 512
Solved Threads: 387
 
Could you show us what you have so far...
srand(time(NULL) ); 
int N = rand()%5001+5000; 
int num; 

for(int i=0;i <N;++i) 

    num = rand()%100+1;

and don't know what else to do

zzjason
Newbie Poster
3 posts since Jan 2010
Reputation Points: 6
Solved Threads: 0
 
Could you show us what you have so far...
#define STRICT
#include <windows.h>
#include <stdio.h>

int main()
{
	unsigned int	ppid	= (unsigned int)GetCurrentProcessId();
	unsigned int	pthid	= (unsigned int)GetCurrentThreadId();
	HANDLE		hThread;
	DWORD		thId;

	//Parent Process and Parent 
printf ("(THREAD2:MAIN):     PID = %5d : THID =%5d : Parent process started.\n",
				(int)ppid, (int)pthid);

	fflush(stdout);

	//Create Thread
	if (hThread) {
		printf ("(THREAD A:MAIN):     Thread ID =%5d created successfully.\n",
				(int)thId);
		fflush(stdout);
	}
	else	{
			printf ("(THREAD2:MAIN):     Function \"CreateThread\" failed with error nbr %d.\n", (int)GetLast Error());
		}




	return 0;}
zzjason
Newbie Poster
3 posts since Jan 2010
Reputation Points: 6
Solved Threads: 0
 

Yeah, right - thanks for spamming the board with your untagged code :( :@

Salem
Posting Sage
Team Colleague
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
 

You will want to use _beginthreadex () to create the two threads. Scroll down to the bottom of that link and it will show you an example of how to create the thread and wait for the thread to exit. After the thread ends call GetExitCodeThread () to get its return value. Those functions are declared in and

The program instructions also state that you have to pass several variables to those threads. The only way you can do that is to create structures to hold the values and pass a pointer to the structure instance as the parameter to _beginthreadex().

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: