in reply to Sharing in fork

i want to share my data among threads, which are created using forks.

Which one is it? Are you using threads or forked processes? I'm guessing the latter. Each process has its own memory space, so changes to a variable in one process isn't going to change the anything in another process. You need to setup a pipe, some shared memory or some other communication channel between the processes if you want to communicate between them. And maybe use a higher level interface over that channel (e.g. Cache::Mmap, forks, etc).

Replies are listed 'Best First'.
Re^2: Sharing in fork
by ajeet@perl (Acolyte) on Mar 23, 2010 at 08:27 UTC
    Thank You Sir for your feedback Right.. I am talking about the latter one. Problem scenario is something like this. A main process will create a queue,initialize head and tail. Now it will fork twice and create two other process. one of them will be responsible for enqueing and other is for dequeing, I had chosen fork to do this, i tried manipulating using reference. So, Sir please suggest a way through which the queue can be shared among both forked process and changes made by one process should be visible by other process. I am stuck at this, I dont want to use thread, for that i need to re-install my perl interpreter,(that i can not do).

    Waiting for your reply...

      I dont want to use thread, for that i need to re-install my perl interpreter

      Then use forks and forks::shared, which uses sockets for inter-process communication.  Believe it, there is no direct way to share variables between child and parent, because each process has its own address space.

        Yeah...I am also thinking to go with fork.

        Need a clarification from your side..the situation that i described,is it well suitable to go with fork..?

        One more thing that...i tied to install forks.pm from CPAN,but it demands for some additional modules. and fails with saying something "/usr/ucb/cc: language optional software package not installed *** Error code 1 make: Fatal error: Command failed for target `forks.o' "
        I searched on Net and found something that this is problem with my C compiler, then i tried to use it without installataion, by creating some perl file in the same directory( correct me,If i am wrong) but fails to do so.
        so please,give some idea that if there is any way to use forks, without installing them, if installation is the last option then proper way to install it..

        Thanks Sir... I am on my way of getting solution

      A reply falls below the community's threshold of quality. You may see it by logging in.
Re^2: Sharing in fork
by ajeet@perl (Acolyte) on Mar 24, 2010 at 05:56 UTC
    Sir, I want to know one thing that, will the installation of forks.pm will affect my base installation of perl?If yes the can i uninstall the package later? I searched net, but does not found any information, which provides information about this...

      What does affect mean here? It's a module. If you don't use it, it doesn't do anything.

      I don't know what's available as tools for uninstalling. It's not something one needs to do, really. Hand removing the .pm and .so/.dll files should be simple enough. You also have to option of installing it to a private directory you can blow away at will.