开发者

Should I have to create a thread if I want to make distributed mutex library?

I am trying to write a simple lock/unlock algorithm that behaves like a mutex in distributed systems with C++.

It will be implemented as a library and users will be able to use it using the interface file.

Assume there are 3 processes {A,B,C}.

Each processors knows other proce开发者_开发百科sses' addresses and ports and so on.

If A wants to lock on some object, it has get permission from other processes, which in this case B and C.

I believe sending and waiting for replies from B, and C won't be a problem, because user will definitely call the function.

But, how should B, and C receive the message?

It is guaranteed that all processes will be alive.

Should there be a separate thread for each processor running listening(polling) to the sockets?

Does that mean if I create a thread in the constructor, and use it while the process is running, and destroying it at the destructor will be just fine?


Should there be a separate thread for each processor running listening(polling) to the sockets?

You should use a library for Inter-Process Communication, unless you intend to build something like that from scratch as an excercise. If you want to build something yourself, read that wikipedia article and maybe some chapters from books on Operating Systems (like Tanenbaum or Silberschatz).

For your specific problem of mutual exclusion in distributed systems, see Maekawa's Algorithm.

Does that mean if I create a thread in the constructor, and use it while the process is running, and destroying it at the destructor will be just fine?

If you plan to implement it like that, why not. Distributed systems often use a layered approach (see http://www.erlang.org/course/error_handling.html in an Erlang tutorial for example). A layer is essentially a collection of communicating and cross-dependent processes, that work together towards a common goal. One of those processes can act as the connection to a lower layer and another process as a connection to a higher layer. You could implement the complete layer in one operating system process using threads, that get created upon process creation and destroyed when destroying the process. It all depends on what you want to achieve and which path you take.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜