slang-users mailing list

[2011 Date Index] [2011 Thread Index] [Other years]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]

Re: [slang-users] fork with shared memory


Thomas Dauser <thomas.dauser@xxxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
> I managed to send information between different processes using the isis 
> functions in fork_socket.sl.
> However, one more question remains unsolved to me: Is there a 
> possibility to create something like a "probe_obj" function, such that I 
> only "recveive" an object if it was acutally sent to me? Functions for 
> receiving objects like fread (and the according higher level functions) 
> always wait until something is actually received.

The isis fork_socket code was written to facilitate function
minimization over multiple CPUs for rapidly producing confidence
maps, etc.  As such it is lacking some of the more generic features
that you have in mind.  Nevertheless, it can be "tricked" into doing
what you want, as the example code below shows.

If you would like to see additional functionality added to
fork_socket, then I suggest that you bring this up on the isis mailing
list <http://space.mit.edu/cxc/isis/mailing_list.html>.

Good luck,
--John

require ("fork_socket");
private define slave_task (s)
{
   % perform a big computation
   sleep (10);
   variable result = [1:10];

   send_msg (s, SLAVE_RESULT);
   send_objs (s, result);
   send_msg (s, SLAVE_EXITING);
   return 0;
}

private define message_handler (s, msg)
{
   switch (msg.type)
     {
      case SLAVE_RESULT:
	s.data = 1;
	@(qualifier("num_results")) += 1;
     }
}

private define one_shot ()
{
   variable x = qualifier ("v");
   if (@x == 0)
     return 0;

   @x = 0;
   return 1;
}

private define check_messages (slist)
{
   foreach (slist)
     {
	variable s = ();
	variable status = select (s.sock, NULL, NULL, 0);
	if ((status == NULL) || status.nready)
	  break;
     }
   then return 0;

   variable x = 1, num_results = 0;
   manage_slaves (slist, &message_handler
		  ; while_=&one_shot, v=&x, num_results = &num_results);
   return num_results;
}

define slsh_main ()
{
   variable slist = new_slave_list ();
   list_append (slist, fork_slave (&slave_task));
   while (0 == check_messages (slist))
     {
	() = fputs (".", stdout); () = fflush (stdout);
	sleep (1);
     }

   foreach (slist)
     {
	variable s = ();
	if (s.data == 1)
	  {
	     variable obj = recv_objs (s);
	     print (obj);
	  }
     }

   manage_slaves (slist, NULL);
}



[2011 date index] [2011 thread index]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]