User:Kernigh: Difference between revisions
Content added Content deleted
(Add Lisp variants; add note about ActionWML and CMake.) |
(This code is in progress.) |
||
Line 27: | Line 27: | ||
[http://wiki.wesnoth.org/ActionWML ActionWML] is the scripting language from the Battle for Wesnoth. [http://www.cmake.org/ CMake] is a build system with its own scripting language. |
[http://wiki.wesnoth.org/ActionWML ActionWML] is the scripting language from the Battle for Wesnoth. [http://www.cmake.org/ CMake] is a build system with its own scripting language. |
||
== In progress == |
|||
<lang c>#include <stdio.h> |
|||
#include <stdlib.h> |
|||
#if defined(_WIN32) |
|||
#include <windows.h> |
|||
#include <process.h> |
|||
/* ARGSUSED */ |
|||
unsigned __stdcall |
|||
run2(void *arg) |
|||
{ |
|||
printf(" %d\n", rand()); |
|||
printf(" %d\n", rand()); |
|||
printf(" %d\n", rand()); |
|||
return 0; |
|||
} |
|||
void |
|||
run(void) |
|||
{ |
|||
HANDLE thread; |
|||
thread = (HANDLE)_beginthreadex(NULL, 0, run2, NULL, 0, NULL); |
|||
if (thread) { |
|||
WaitForSingleObject(thread, INFINITE); |
|||
CloseHandle(thread); |
|||
} else |
|||
puts("Error!"); |
|||
} |
|||
#elif defined(__unix__) |
|||
#include <pthread.h> |
|||
/* ARGSUSED */ |
|||
void * |
|||
run2(void *arg) |
|||
{ |
|||
printf(" %d\n", rand()); |
|||
printf(" %d\n", rand()); |
|||
printf(" %d\n", rand()); |
|||
return NULL; |
|||
} |
|||
void |
|||
run(void) |
|||
{ |
|||
pthread_t thread; |
|||
if (pthread_create(&thread, NULL, run2, NULL) || |
|||
pthread_join(thread, NULL)) |
|||
puts("Error!"); |
|||
} |
|||
#else |
|||
#error Port run() to your system. |
|||
#endif |
|||
/* ARGSUSED */ |
|||
void |
|||
three(void) |
|||
{ |
|||
printf(" %d\n", rand()); |
|||
printf(" %d\n", rand()); |
|||
printf(" %d\n", rand()); |
|||
} |
|||
int |
|||
main() |
|||
{ |
|||
puts("Thread A:"); |
|||
run(); |
|||
puts("Thread B:"); |
|||
run(); |
|||
return 0; |
|||
}</lang> |
|||
<pre>Thread A: |
|||
41 |
|||
18467 |
|||
6334 |
|||
Thread B: |
|||
41 |
|||
18467 |
|||
6334</pre> |