emp-toolkit/emp-sh2pc

Run two party on one terminal?

Closed this issue · 7 comments

I am experimenting multiplication by two parties using triplets. Here is my code:

NetIO *io1, *io2;

void foo(int port, int party)
{
io1 = new NetIO(party==ALICE ? nullptr : "127.0.0.1", port);
io1->set_nodelay();

}

void bar(int port, int party)
{
io2 = new NetIO(party==ALICE ? nullptr : "127.0.0.1", port);
io2->set_nodelay();

}

int main(int argc, char** argv){

//one terminal
int port = 12345;
int party1 = 1;
int party2 = 2;

std::thread first_io (foo,port,party1);     // spawn new thread that calls foo()
std::thread second_io (bar,port,party2);  // spawn new thread that calls bar(0)
std::cout << "main, foo and bar now execute concurrently...\n";
// synchronize threads:
first_io.join();                // pauses until first finishes
second_io.join();               // pauses until second finishes

}

As you can see, I am trying to create this connection without running the terminal twice. However, the program always PAUSE with message
"main, foo and bar now execute concurrently...
connected
connected"

What should I do?

It seems fine since "connected" means that the NetIO has been established.

Any code after second_io.join()? May need flushing.

I can only suggest some possibilities.

I am firstly wondering whether, when first_io.join() is completed, the NetIO object created by foo indeed is released, and the connection is terminated due to the destruction function of NetIO (but this will unlikely cause a pause).

Do you mind adding some debugging "printf"?

  • before and after io2->set_nodelay();
  • before and after second_io.join();

Might provide some insights.

Flushing function of a NetIO object flush() is here: https://github.com/emp-toolkit/emp-tool/blob/master/emp-tool/io/net_io_channel.h

Thanks weikeng, I will take a look at it.

Thanks, I just need to flush the io and it now works.

That's interesting. Someone tried something similar a year ago but failed. Do you mind opening a pull request with a working example? Thanks!!

On Wed, Apr 8, 2020 at 1:37 PM w1001766 @.***> wrote: Thanks, I just need to flush the io and it now works. — You are receiving this because you commented. Reply to this email directly, view it on GitHub <#17 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AARKGCSJ22YMMYZUYYOJYULRLS77RANCNFSM4MC26JUA .

Hi wangxiao1254. I don't have the permission for dev branch, so I just send my code to your email.