Sponsored Content
Top Forums Programming how to create variable for all thread in c++ Post 302311054 by vip_a1 on Monday 27th of April 2009 07:33:41 PM
Old 04-27-2009
how to create variable for all processes in c++

hello
I have this code
Code:
	
        #include <sys/types.h>
	#include <unistd.h>			
	#include <iostream>
	#include <pthread.h>
	#include<cstring>
	using namespace std;

	

	int var1=0;  
   
	void doSomething()  
	{
		var1 = 5;
		cout<<"Do S :"<<var1<<endl;	
		sleep(1);
		var1 =7;

		cout<<"Do S :"<<var1<<endl;	
		sleep(1);

		var1 =10;
		cout<<"Do S l :"<<var1<<endl;	
		sleep(1);
     
	 }  
   
	int main()  
	 {  
   
	     if (fork() != 0)  
		     doSomething();   
		 else
		     {
			cout << var1 << endl; sleep(1);
			cout << var1 << endl; sleep(1);
			cout << var1 << endl; sleep(1);
			cout << var1 << endl; sleep(1);
			}
   
		  return 0;  
	 }

my problem is
when doSomthing function change the variable var1 at the child process it doesn't change at the parent process

is there any way to make a global variable for all processes

thanks

Last edited by vip_a1; 04-28-2009 at 11:41 AM..
 

10 More Discussions You Might Find Interesting

1. Programming

TZ variable set within thread

Hello all, I'm going to be using some of the date functions from time.h to do some time stamping. I will be getting a time and date from the header of a TIFF file. I will need to be able create a time for each time zone in the U.S. The source of the time stamp will be in GMT. What I'd like to do... (2 Replies)
Discussion started by: shldBcding
2 Replies

2. 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

3. Shell Programming and Scripting

create variable name based on another variable's value

Hello, I am needing to create a variable and assign it a value based on the value of a previosly defined variable... I am using KSH.. Example: VAR1=COMPUTER1 I need another variable like ${VAR1}_FLAG="Y", so it would actually be COMPUTER1_FLAG="Y". I will be looping through many values in... (2 Replies)
Discussion started by: benefactr
2 Replies

4. 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

5. UNIX for Advanced & Expert Users

Ksh Create Thread

I think I know the answer but I'll ask and see if someone with more expertise can share new light on this topic: Does Ksh have the capability to create new threads (not processes) and/or offer some multiplexing on named pipes? Thanks for your assistance! ~sreyes27 (2 Replies)
Discussion started by: sreyes27
2 Replies

6. Programming

Unable to create a UDP client from thread?

I try to initial a UDP client from threading, but it doesn't work? why? These codes from the textbook #define ECHOMAX 255 /* Longest string to echo */ #define TIMEOUT_SECS 2 /* Seconds between retransmits */ #define MAXTRIES 5 /* Tries before giving up */... (3 Replies)
Discussion started by: sehang
3 Replies

7. Post Here to Contact Site Administrators and Moderators

How to Create a New Thread

please tell me how can i post a new post. i am not getting any option to post a new question. any suggestion is highly appreciated. thanks, Arpit (1 Reply)
Discussion started by: thearpit
1 Replies

8. UNIX for Advanced & Expert Users

Pthread attr setting doesn't work before thread create?

Hello everyone, I created a test program for pthread priority set. Here's the code, very simple, 60 lines only. I've tried this prog on my Fedora 13(on vbox), and on my 6410 arm linux 2.6.36. Both the same result. Both environments are using root privileges. Can any body tells me why the... (15 Replies)
Discussion started by: ss1969
15 Replies

9. Forum Support Area for Unregistered Users & Account Problems

I am still meet a problem when I want to reply or create a new thread

Hi, Scott, I am still meet a problem when I want to reply or create a new thread in "Shell Programming and Scripting" Forum, It reminds that: To create new threads in this forum your post count must be 10 or greater. You currently have 2 posts. To my surprise, I posted a thread in "Shell... (4 Replies)
Discussion started by: weichanghe2000
4 Replies

10. Forum Support Area for Unregistered Users & Account Problems

Unable to create new thread

Hi. I registered, but when trying to post, I get ... "Sorry, you do not have enough Bits to post a new thread" Google & Forum search showed some hits, but no solution. Please advide. Thanks! (1 Reply)
Discussion started by: gehe
1 Replies
MYSQLI_STMT(3)								 1							    MYSQLI_STMT(3)

The mysqli_stmt class

INTRODUCTION
Represents a prepared statement. CLASS SYNOPSIS
mysqli_stmt mysqli_stmt Properties o int$mysqli_stmt->affected_rows o int$mysqli_stmt->errno o array$mysqli_stmt->error_list o string$mysqli_stmt->error o int$mysqli_stmt->field_count o int$mysqli_stmt->insert_id o int$mysqli_stmt->num_rows o int$mysqli_stmt->param_count o string$mysqli_stmt->sqlstate Methods o mysqli_stmt::__construct (mysqli $link, [string $query]) o int mysqli_stmt::attr_get (int $attr) o bool mysqli_stmt::attr_set (int $attr, int $mode) o bool mysqli_stmt::bind_param (string $types, mixed &$var1, [mixed &$...]) o bool mysqli_stmt::bind_result (mixed &$var1, [mixed &$...]) o bool mysqli_stmt::close (void ) o void mysqli_stmt::data_seek (int $offset) o bool mysqli_stmt::execute (void ) o bool mysqli_stmt::fetch (void ) o void mysqli_stmt::free_result (void ) o mysqli_result mysqli_stmt::get_result (void ) o object mysqli_stmt::get_warnings (mysqli_stmt $stmt) o mixed mysqli_stmt::prepare (string $query) o bool mysqli_stmt::reset (void ) o mysqli_result mysqli_stmt::result_metadata (void ) o bool mysqli_stmt::send_long_data (int $param_nr, string $data) o bool mysqli_stmt::store_result (void ) PHP Documentation Group MYSQLI_STMT(3)
All times are GMT -4. The time now is 01:53 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy