Skip to content

Commit 3cb2a0e

Browse files
committed
* 'master' of https://github.com/petercorke/simple-threads-coder: Update README.md Update README.md Update README.md Update README.md Update README.md
2 parents 99f417b + b3d2422 commit 3cb2a0e

File tree

1 file changed

+38
-5
lines changed

1 file changed

+38
-5
lines changed

README.md

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,20 @@ Copyright © 2018 Peter Corke
44

55
STL provides POSIX thread primitives to MATLAB® code that has been converted to C code using the MATLAB Coder® toolchain. It allows multi-threaded operation on Linux and MacOS platforms (I don't have access to Windows to test).
66

7-
STL provides threads, semaphores, mutexes, high resolution delay, timers (Linux only), and logging.
7+
STL provides threads, semaphores, mutexes, high resolution delay, timers (Linux only), logging and an embedded web server that supports templating.
88

99
To use this you must have a licence for MATLAB® and MATLAB Coder®.
1010

1111
More details in the [project Wiki](https://github.com/petercorke/simple-threads-coder/wiki).
1212

13-
## Collaborate
13+
Also listed in [MATLAB File Exchange](https://www.mathworks.com/matlabcentral/fileexchange/68648-simple-threads-coder).
1414

15-
If you download and test this, please send me your feedback. If you're interested in helping with development, even better, please contact me and we can make a plan. A non-exhaustive list of development topics is at the end of this document.
15+
## Collaborate
1616

17+
If you download and test this, please send me your feedback. If you're interested in helping with development, even better, please contact me and we can make a plan. A non-exhaustive list of short- and long-term development topics is on the [Wiki](https://github.com/petercorke/simple-threads-coder/wiki).
1718

1819

19-
## An example
20+
## Example 1: Threading
2021

2122
Consider this example with one main function and three additional threads. You can find this in `examples/threads`.
2223

@@ -104,7 +105,7 @@ function thread3() %#codegen
104105
end
105106
```
106107

107-
## Building and running the application
108+
### Building and running the application
108109

109110
```matlab
110111
>> make
@@ -175,5 +176,37 @@ got 4 arguments
175176
2018-08-27 09:25:09.485149 [thread3] waiting for semaphore #0 <sem1>
176177
```
177178

179+
## Example 2: Web server
180+
```matlab
181+
function myserver() % called on every page request
182+
switch (webserver.url())
183+
case '/'
184+
webserver.html('hello world'); % display a simple string
185+
case '/bob'
186+
webserver.html('<html><body>hello <b>from</b> /bob</body></html>');
187+
a = webserver.getarg('a'); % test for argument of the form ?a=X
188+
if ~isempty(a)
189+
stllog('a = %s', cstring(a));
190+
end
191+
case '/alice'
192+
vals.a = 1;
193+
vals.b = 2;
194+
webserver.template('templates/alice.html', vals); % create a templated response
195+
case '/duck':
196+
webserver.file('duck.jpg', 'image/jpeg'); % return an image
197+
```
198+
199+
The template file looks like
200+
```html
201+
<html>
202+
<body>
203+
<p>This is a test page</p>
204+
<p>a = <TMPL_VAR name="a"></p>
205+
<p>b = <TMPL_VAR name="b"></p>
206+
</body>
207+
</html>
208+
```
209+
and the values of the fields of the struct `vals` are substituted for the corresonding named `TMPL_VAR` tags.
210+
178211
---
179212
Created using Sublime3 with awesome packages `MarkdownEditing`, `MarkdownPreview` and `Livereload` for WYSIWYG markdown editing.

0 commit comments

Comments
 (0)