Variables betwen pthreads ?


 
Thread Tools Search this Thread
Top Forums Programming Variables betwen pthreads ?
# 1  
Old 11-18-2006
Variables betwen pthreads ?

I have a doubt .. ( maybe I don't know ..)

Let's say , we got the folowing example ( to understand better what I mean ).

We got two POSIX threads ( pthreads ) , one receives some strings and creates a menu ( for that strings , scrollable menu ) , and another one check's to see if it has to scroll the menu , or scroll down some strings.

I mean , the menu with strings is created in one pthread ( lets say it 1 ) , and simultanous checking if to scroll down strings or even menu is done is pthread 2 . How can pthread 2 know the location ( I mean pointer ) of the menu & window used in pthread 1 ? I mean a menu and a window are created in pthread 1 and fill out , at regular intervals , but I want pthread 2 to local variables used in pthread 1 to..

something like :

Code:
 p1 = pthread_create(&thread1, NULL , Check, NULL);
 p2 = pthread_create(&thread2, NULL , Receive ,NULL);

and ..

void *Check()
{
int c;

 if (c = wgetch(wind)) == KEY_DOWN )
      {
                menu_driver(menu, REQ_DOWN_ITEM);
                wrefresh(wind)
	break;
}

...
}

and ..

void *Receive()
{
WINDOW *wind;
MENU *menu;
ITEM *item;

< create window  wind  and menu   menu >

}

What I want ? I want Check void to use wind and menu from Receive .. Can I do this ( multithreading ) ?


Thanks in advance ! Smilie
# 2  
Old 11-19-2006
Yes you can. Threads share memory. Just make sure that you declare the variables before you invoke the threads.
# 3  
Old 11-19-2006
Oh ya ! True . I have already implemented the idea !

Thanks ! Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to compare ,diff and remove betwen 2 files

Hi Friends Need your expertise. Command to check the difference and compare 2 files and remove lines . example File1 is master copy and File2 is a slave copy . whenever i change, add or delete a record in File1 it should update the same in slave copy . Can you guide me how can i accomplish... (3 Replies)
Discussion started by: ajayram_arya
3 Replies

2. Shell Programming and Scripting

redirecting to stdout in betwen command

can anyone help me in making singleline command for Capital Letters are folders ,small letter are files X,Y,Z are subfolders of A as shown below A - X,Y,Z Folder X has three files a.txt,b.txt,c.txt similarly Y,Z. as shown below X- a.txt,b.txt,c.txt Y- a.txt,b.txt,c.txt Z-... (4 Replies)
Discussion started by: phoenix_nebula
4 Replies

3. UNIX for Advanced & Expert Users

Pthreads-Conditional variables

Hello, consider a bunch of threads which want to execute a while loop in parallel but after each iteration of while loop, we need a synchornization.That is, we have a global count varibale which is equal to zero at beginig of each iteration and at the end of each iterartion this variable... (0 Replies)
Discussion started by: Behnaz
0 Replies

4. Programming

Problem with pthreads

hi i have a code: I found that after exiting from child thread memory isn't freed. I commented everything which is "some actions" here, so thread's function contains only two lines. But it doesn't help. What do I do wrong? Thanks a lot (3 Replies)
Discussion started by: sery0ga
3 Replies

5. HP-UX

pthreads

Hi! I'm linking my hpux code using -lpthread (gcc), yet it references libpthread_tr.1, the debug version of the pthread lib. How do I force it to use pthreads? Thanks, :) (3 Replies)
Discussion started by: zackz
3 Replies

6. UNIX for Dummies Questions & Answers

Question on Pthreads

How to give superuser privileges while setting the attributes like pthread_attr_setschedpolicy( )?? Even with normal user mode ,it is working fine for me.But in man pages, they have specied that to set the scheduling policy as SCHED_FIFO, the process should have superuser privileges. (0 Replies)
Discussion started by: yashavant.a
0 Replies

7. Programming

PThreads

I have created a thread program, it is attached. My problem is that I need to loop this program multiple times, and basically reset everything including the threads created previously. I try to loop the program, the first run is fine, as always, but the second run of the program, the initialize... (0 Replies)
Discussion started by: justgotthis
0 Replies

8. Programming

pthreads

howcome that pthtreads spawn 2 extra processes? I'm kind of new with pthreads but fork() did not act like this. Anyone who can give me a technical explanation of what happends with mother / daughter processes? Best regards Esaia. (2 Replies)
Discussion started by: Esaia
2 Replies

9. Programming

pthreads

Does any one no of some good web site which will explain about how to program using pthreads in a UNIX enviroment? (6 Replies)
Discussion started by: fishman2001
6 Replies

10. UNIX for Advanced & Expert Users

PThreads

Can anyone explain me how to use pthread_key_create() , pthread_setspecific(), pthread_getspecific() and pthread_key_delete () routines in pthreads. Kindly state by an example. (3 Replies)
Discussion started by: S.P.Prasad
3 Replies
Login or Register to Ask a Question