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.

Salem commented: Thread hijack and zero effort failure! -4

Recommended Answers

All 5 Replies

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

commented: They just did! ;) It's just not enough. +18

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

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;}

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 <process.h> and <windows.h>

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().

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.