Thread: How To Initialize concurrent processes in C?

  1. #1
    POeT GuY Matus's Avatar
    Join Date
    Feb 2008
    Location
    Bz
    Posts
    235

    Question How To Initialize concurrent processes in C?

    I wrote a program in BACI, now I'm gona write in C. But my question to start off his how to initialize concurrent processes? In BACI i did it like this:

    Code:
    cobegin {
    
    manager(); teller1(); teller2(); teller5();teller3();teller4();
    
    }
    This would simulate any of the processes randomly.
    PoEms R InsPiRatiOns of LIfE ExpErienCes!!


  2. #2
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    Quote Originally Posted by Matus View Post
    I wrote a program in BACI, now I'm gona write in C. But my question to start off his how to initialize concurrent processes? In BACI i did it like this:

    Code:
    cobegin {
    
    manager(); teller1(); teller2(); teller5();teller3();teller4();
    
    }
    This would simulate any of the processes randomly.
    After a quick Google, it seems this would simulate all of the "processes", concurrently.

    The C(/C++) equivalent is threads. There are several libraries out there, which depend on OS, etc. pthreads works almost everywhere, including windows, if you find the appropriate library. (Otherwise, Windows has its own API for threading)
    The Boost library has some classes for threads as well.
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  3. #3
    Registered User Maz's Avatar
    Join Date
    Nov 2005
    Location
    Finland
    Posts
    194
    Quote Originally Posted by Cactus_Hugger View Post
    After a quick Google, it seems this would simulate all of the "processes", concurrently.

    The C(/C++) equivalent is threads. There are several libraries out there, which depend on OS, etc. pthreads works almost everywhere, including windows, if you find the appropriate library. (Otherwise, Windows has its own API for threading)
    The Boost library has some classes for threads as well.
    Actually threads are quite different from processes (at least when we consider what I understand with a process). Threads have full access to each other's address spaces, whereas processes do not. So with threads, it is possible to share data via global variables. It is also possible to have a wild pointer in one thread, which trashes other thread's stack.

    So if you want to have concurrent processes, it is possible to write independent executables, and launch them via some standard function (like system() ), or then you can use tools your OS gives to you. (On linux, see fork() ).

  4. #4
    POeT GuY Matus's Avatar
    Join Date
    Feb 2008
    Location
    Bz
    Posts
    235
    :S lol thought it was gona be simple, now im more puzzled, i'll try googling in a bit
    PoEms R InsPiRatiOns of LIfE ExpErienCes!!


  5. #5
    apprentiCe
    Join Date
    Oct 2008
    Location
    Hyderabad,India
    Posts
    136
    for threads almost all compilers have posix threads...found in the library pthread.h

    as for process,it depends how OS spawns a process unix uses fork() to spawn a child process...unix , as far as i have come across does not have concurrent processes,i.e no "normal process",except "init" can spawn on its own and run independently reporting to no one...every process has a parent and a parent can have child processes.BUT processes can run concurrently or they can be suspended to wait for its child...

    as for windows? i have no idea...
    Code:
    printf("%c%c%c%c%c%c%c",0x68,0x68^0xd,0x68|0x4,0x68|0x4,0x68|0xf,0x68^0x49,0x68^0x62);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 34
    Last Post: 05-27-2009, 12:26 PM
  2. Processes not dying
    By Elkvis in forum Linux Programming
    Replies: 12
    Last Post: 04-23-2008, 08:59 AM
  3. freeing problem with concurrent processes
    By alavardi in forum C Programming
    Replies: 2
    Last Post: 03-07-2005, 01:09 PM
  4. binary tree of processes
    By gregulator in forum C Programming
    Replies: 1
    Last Post: 02-28-2005, 12:59 AM
  5. Unix processes
    By J-Dogg in forum Linux Programming
    Replies: 1
    Last Post: 03-24-2003, 05:42 PM