Guest User

Untitled

a guest
Jan 21st, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.11 KB | None | 0 0
  1. module main;
  2.  
  3. import tango.core.Exception;
  4. import tango.io.Stdout;
  5. import tango.core.Memory;
  6. import tango.stdc.stdlib;
  7. import tango.util.log.Log;
  8. import tango.sys.Process;
  9. import tango.core.Thread;
  10. import tango.stdc.posix.unistd;
  11. import ocean.util.log.Trace;
  12.  
  13. void main()
  14. {
  15.     void doFork ( )
  16.     {
  17.         while (true)
  18.         {
  19.             Trace.formatln("Suspending");
  20.             thread_suspendAll();
  21.             if ( fork() != 0 )
  22.             {
  23.                 Trace.formatln("Forked");
  24.                 thread_resumeAll();
  25.                 Trace.formatln("Resuming");
  26.             }
  27.             else
  28.             {
  29.                 Trace.formatln("Forked-Child, Exiting");
  30.                 exit(1);
  31.             }
  32.         }
  33.     }
  34.  
  35.     void doMalloc ( )
  36.     {
  37.         while ( true)
  38.         {
  39.             Trace.formatln("Malloc, allocating");
  40.             auto mem = malloc(10000);
  41.             Trace.formatln("Malloc, freeing");
  42.             free(mem);
  43.         }
  44.     }
  45.  
  46.     auto fork   = new Thread(&doFork);
  47.     auto malloc = new Thread(&doMalloc);
  48.  
  49.     malloc.start;
  50.     fork.start;
  51. }
Add Comment
Please, Sign In to add comment