Sponsored Content
Top Forums Shell Programming and Scripting Deliver values to Thread function Post 302804197 by jimm_the_h on Wednesday 8th of May 2013 07:06:58 AM
Old 05-08-2013
Deliver values to Thread function

Hello,
I hope you can help me with my problem.
I've written a programm which creates a thread. The main programmm creates 10 int and float values. The fucnction should give the values out.
May big problem ist that the delivery to the function is not working.
Where ist my fault?
How can I make easier?
Thank you for your help.

Code:
void funktion1 (void *arg1)
{
	
	printf("Int-Zahl= %i",arg1);
	printf("[TID:%li,PPID:%i] Threadfunktion1 \n",syscall(SYS_gettid),getppid() );
	pthread_exit(NULL);
}

int main()
{	
	struct Zahlen{int z1;float z2;};

	struct Zahlen Zahl;

	pthread_t ptr1, ptr2, ptr3;
	int res1;
	int res2; 
	int bes1;
	int bes2;


	// reine Threadzeile
	res1 = pthread_create(&ptr1, NULL, (void *)&funktion1,(void *)Zahl.z1);

	//Fehlerabfrage Thread3
		if(res1 != 0)
	{
		perror("Thread creation failed!");
	}
	int i;	
	for(i = 0; i<=10;i++)
	{
		Zahl.z1 = random() % 100; //Int Zahl 1-100 erzeugt
		Zahl.z2 =(float)rand() / RAND_MAX; //Float Zahl 0-1 erteugt
		printf("[TID: %li, PID: %i]int-Wert: %i  float-Wert: %f \n",syscall(SYS_gettid), getpid(), Zahl.z1, Zahl.z2);
	}
	bes1 = pthread_join(&ptr1, NULL);
	
	/*if (bes1  !=0) 
		{ 
			perror("Thread join failed");		
			exit(1); 
		}
	return 0;
}


Last edited by Scott; 05-08-2013 at 11:21 AM.. Reason: Please use code tags
 

10 More Discussions You Might Find Interesting

1. HP-UX

create thread C with JNI function with JAVA

Hello, J create a thread C with a JNI function via JAVA. J have the following message (but not in each time): Someone has an idea ? Thank. Unexpected Signal : 4 occurred at PC=0x78C103E0 Function= Library=(N/A) NOTE: We are unable to locate the function name... (0 Replies)
Discussion started by: AUBERT
0 Replies

2. Programming

create a thread from a returning function

hi all, my requirement is to create a thread by calling another function. i.e i dont call pthread_create directly from main, but by calling another function (createThd - below ), from main. Example: void *thread_function(void *arg) { /* thread function */ int i; rc =... (3 Replies)
Discussion started by: wolwy_pete
3 Replies

3. Programming

returning multiple values from a function in C

hi how can I return multiple values from a C function. I tried the following: #include <stdio.h> void foo(int id, char *first_name, char *last_name) { /* this is just an example to illustrate my problem... real code makes use of the "id" parameter. */ first_name = (char... (8 Replies)
Discussion started by: Andrewkl
8 Replies

4. Shell Programming and Scripting

passing values to function in Ksh

Hi, I'm trying to work on the script given below #!/bin/ksh -x pfile() { echo "$1" } touch smp19 echo "Hi" > smp19 result=$(pfile $smp19) echo $result As highlighted , when i pass $smp19 as parameter ,it does not display the output.However when i try giving "Hi" instead... (2 Replies)
Discussion started by: Sheema
2 Replies

5. Shell Programming and Scripting

Function returns wrong values - solved

Hi I have a small function which returns a wrong value. The function tries to make a connection to oracle database and tries to get the open_mode of the database in the variable status. However when a database is down the value of the status column is set to READWRITE i am not sure why. I... (0 Replies)
Discussion started by: xiamin
0 Replies

6. Shell Programming and Scripting

how to capture oracle function returning 2 values in unix

i have an oracle function which returns two values, one is the error message if the function encounters anything and another one which returns a number i need to capture both and pass it on to unix shell script how to do it (2 Replies)
Discussion started by: trichyselva
2 Replies

7. Programming

Thread function local variables

As I know threads share the memory. But, what about the local variables in the thread function? if i call multiple threads would they allocate seperate local variables for themselves? like thread_func() { int i, j; string... } Are the above local variables defined for each of... (1 Reply)
Discussion started by: saman_glorious
1 Replies

8. Programming

Passing multiple values from a function in C

I know multiple values can be returned from a function in C like this: char **read_file ( char * , unsigned long int * );//this is the function prototypeunsigned long int number_of_words = 0;//variable defined in main() and initialized to 0words_from_dictionary = read_file ( "dictionary.dit" ,... (2 Replies)
Discussion started by: shoaibjameel123
2 Replies

9. Programming

unable to use a function to crate a joinable thread

In my program, threads may be created when some events trigger. So I can't create threads on initialization. Theremore,I write a createThread() function to create thread. However, it is blocking at first call and don't run anymore? why? #include <pthread.h> #include <stdio.h> #include... (4 Replies)
Discussion started by: sehang
4 Replies

10. UNIX for Dummies Questions & Answers

E-mail will not deliver

I am able to send mail to my gmail account and one or two other accounts, but not to my isp e-mail account and another domain I have set up. I am trying to send from VsiFaxServer@ssc.local. And also from root@ssc.local using the mail command at the prompt. When I check the new messages, I found the... (23 Replies)
Discussion started by: smithssc
23 Replies
PS_SHADING(3)						     Library Functions Manual						     PS_SHADING(3)

NAME
PS_shading -- Create shading SYNOPSIS
#include <pslib.h> int PS_shading(PSDoc *psdoc, const char *shtype, float x0, float y0, float x1, float y1, float c1, float c2, float c3, float c4, const char *optlist) DESCRIPTION
This function creates a shading which can be used by PS_shfill(3) or PS_shading_pattern(3). The type of shading can be either `radial' or `axial'. Each shading starts with the current fill color and ends with the given color values passed in the parameters c1 to c4 (see PS_setcolor(3) for their meaning). The coordinates x0, y0, x1, y1 are the start and end point of the shading. If the shading is of type `radial' the option list must also contain the parameters r0 and r1 with the radius of the start and end circle. The color of the shading can be in any color space except for `pattern'. RETURN VALUE
Returns the identifier of the shading or zero in case of an error. The identifier is a positiv number. SEE ALSO
PS_shfill(3), PS_shading_pattern(3) AUTHOR
This manual page was written by Uwe Steinmann uwe@steinmann.cx. PS_SHADING(3)
All times are GMT -4. The time now is 11:41 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy