2014-10-28 2 views
0

두 개의 프로세스 (프로세스 1과 2)를 수행하는 방법을 이해할 수 없으면 개별 실행 파일과 교환 메시지가 구현됩니다. 뭔가 (1.Hello 2.Hi 1. 어떻게 지내세요? ...).두 개의 실행 파일 (.dis) 파일이있는 두 개의 스레드 림보 (프로그래밍 언어)

아래 코드는 두 스레드가 텍스트 파일에서 메시지를 교환하는 방법을 보여줍니다. 텍스트 파일 대신에 서로 통신하는 실행 파일 (.dis)이 필요합니다.

implement LThread; 
include "sys.m"; 
include "bufio.m"; 
include "draw.m"; 

sys:Sys; 
FD: import Sys; 
stOut: ref Sys->FD; 

bufio:Bufio; 
Iobuf:import bufio; 

LThread:module{ 
    init: fn(nil: ref Draw->Context, nil: list of string); 

    process: fn(pName: string); 
}; 

init(nil: ref Draw->Context, nil: list of string) { 
    sys=load Sys Sys->PATH; 
    bufio=load Bufio Bufio->PATH; 

    spawn process("processA.txt"); 
    sys->sleep(10); 
    spawn process("processB.txt"); 
} 
process(pName: string) { 

    file_buf:ref Iobuf; 
    file_buf = bufio->open(pName, sys->ORDWR); 

    temp_line:string; 
    temp_line=" "; 

    while (temp_line != nil){ 
    temp_line=file_buf.gets('\n'); 
    sys->sleep(200); 
    sys->print("%s \n",temp_line); 
    } 
} 

아마도 모듈을 사용하여 잘 모르겠습니다.

+0

코드에는 2 개의 프로세스가 구현되어 있으며 처리 방법을 알아야합니다. 당신은 그 코드가 2 개의 스레드를 보여 주며 거기에 2 개의 프로세스가 있다는 것을 알 수 있습니다. 코드가하는 일과 당신의 문제는 무엇인지 구체적으로 말할 수 있습니까? – Lucian

+0

2 개의 실행 파일 중 2 개의 프로세스를 호출해야하며이 프로세스가 병렬로 작동해야합니다. 실행 파일을 호출하는 방법을 모르겠습니다. – Gleb

답변

0

내가 원하는 것을 찾았습니다. 자체 인터페이스는 명령 모듈의 유형을 가지며 실행되는 항목의 유형입니다.

exec의 행에서 cmd는 인수 목록의 첫 번째 단어로 설정되고 .dis 문자열이 연결됩니다 (Limbo 객체 프로그램 파일의 이름은 일반적으로이 접미사를 사용하여 지정됩니다) . 정보를 얻었습니다 : "The Limbo Programming Language".

exec(ctx: ref Draw->Context, args: list of string){ 
     c: Command; 
     cmd,file: string; 

     cmd = hd args;  

     file = cmd + ".dis"; 
     c = load Command file; 
     if(c == nil) 
      c = load Command "/dis/"+file; 

     if(c == nil) { 
      sys->print("%s: not found\n", cmd); 
      return; 
     } 
     c->init(ctx, args); 
} 
관련 문제