English 中文(简体)
不同进程之间的信息协调
原标题:Synchronizing message queue between processes

I m trying to implement a program that has a producer and N (N >= 1) workers. They communicate using a message queue. The idea is that the producer sends to the queue "tasks". The workers do a msgrcv() call to get a task and execute some code. After the worker accomplish the task it sends to the queue the result of the computation. The producer will get this message and save the results.

I m 采用POSIX电线,生产商和工人同时工作。

The problem behind this program is that exists a scenario that compromises the communication. Each message has a size of ~5000 bytes. The maximum queue size is ~16000 bytes in UNIX Systems, which is the case.

The scenario is: There are 3 tasks in the queue (5000*3 = 15000 bytes). Some worker get one message from the queue (now the queue has 10000 bytes). The worker starts executing the task and, due to the amount of bytes that a worker has to process in each task, the producer sends to the queue another message (the queue is now full). Now after the task is complete the worker tries to send the result to the queue and becomes blocked (the queue is full). The producer tries to send another task to the queue and becomes blocked too.

如果我只与一名工人共同实施这一方案,这种设想很可能发生。

是否有人想避免这种情况?

最佳回答

如果你能够改变定点大小、使用点数或使用不同的推荐标数,那么将如何减少数据?

你可将实际数据放在共享记忆器或临时档案中。 然后,你不把数据放在电文中,而是用文件名称或共享记忆标名,而是用电文加以抵消。 然后,生产者在获得结果后可以清理。

不一定要分享记忆或临时档案,但想法是把数据放在信息以外的其他地方,并在电文中列入其他程序获取信息所需要的任何信息。

问题回答

d 要么为客户使用第二个电线——>服务器响应或限值(字号——传真)作为安全号码。





相关问题
Fastest method for running a binary search on a file in C?

For example, let s say I want to find a particular word or number in a file. The contents are in sorted order (obviously). Since I want to run a binary search on the file, it seems like a real waste ...

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

Tips for debugging a made-for-linux application on windows?

I m trying to find the source of a bug I have found in an open-source application. I have managed to get a build up and running on my Windows machine, but I m having trouble finding the spot in the ...

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...

Encoding, decoding an integer to a char array

Please note that this is not homework and i did search before starting this new thread. I got Store an int in a char array? I was looking for an answer but didn t get any satisfactory answer in the ...

热门标签