1 |
On Wednesday, August 13, 2014 08:19:19 PM Grant Edwards wrote: |
2 |
> On 2014-08-13, Alec Ten Harmsel <alec@××××××××××××××.com> wrote: |
3 |
> >> I may have to stick with sockets when I want to block until some event |
4 |
> >> happens. |
5 |
> > |
6 |
> > To be clear, do you want to block or sleep/yield until an event |
7 |
> > happens? |
8 |
> |
9 |
> I don't see the difference -- isn't that what a blocking call does: |
10 |
> sleep/yield until some event happens? |
11 |
> |
12 |
> > I'm sorry for not being too helpful. Just one last question: Can you |
13 |
> > describe what exactly your code is supposed to do, or is it something |
14 |
> > that you can't talk about because it's a work thing? I don't care |
15 |
> > either way, but I'm just curious because it seems you need to |
16 |
> > optimize quite a bit. |
17 |
> |
18 |
> One process implements a communications protocol that is maintaining |
19 |
> communications links with a handful of slave devices connected to |
20 |
> serial ports running at baud rates up to 230400 baud (38400 is the |
21 |
> most common). There are typically one (or maybe two) hundred messages |
22 |
> per second being exchanged with each slave device. I'll call that |
23 |
> process the server. |
24 |
|
25 |
1 process (server) |
26 |
Do you have seperate threads per slave device? Then each thread can handle the |
27 |
incoming messages when they arrive. |
28 |
|
29 |
> There are other client processes that want to access the slaves and |
30 |
> the inforamation being received from them. Some of the clients just |
31 |
> want to do low-frequency transactions for configuration/diagnostic |
32 |
> purposes, and Unix domain sockets work fine for that. |
33 |
|
34 |
Have the client processes connect to a seperate thread for the communication. |
35 |
Then set up a shared memory between the relevant slave-device-thread and the |
36 |
client-process-thread(s) |
37 |
I would create 2 different memory sets. One that is written only by the slave- |
38 |
device-thread. And the other only by the client-process-thread(s) |
39 |
|
40 |
That way, the client-process-threads can read that to get the current status. |
41 |
And the slave-device can read the "commands" from the client-process-thread(s) |
42 |
|
43 |
> Other clients may want to wake up every time a certain high frequency |
44 |
> event happens. That's where I'm trying to use condition variables. |
45 |
> |
46 |
> Other clients will periodically (typically once every 5-50 ms) want to |
47 |
> see the most recent copy of a particular received message. I'm |
48 |
> thinking about using shared memory and rwlocks for that, but I haven't |
49 |
> figured out how to deal with the case where a process aborts while |
50 |
> holding a lock. |
51 |
|
52 |
This sounds similar to an application I wrote a long time ago to deal with |
53 |
connecting a desktop application to a telecomms server dealing with all the |
54 |
phone connections in a company. |
55 |
|
56 |
-- |
57 |
Joost |