summaryrefslogtreecommitdiff
path: root/test/threads.cxx
diff options
context:
space:
mode:
authorMichael R Sweet <michael.r.sweet@gmail.com>2006-01-06 16:53:04 +0000
committerMichael R Sweet <michael.r.sweet@gmail.com>2006-01-06 16:53:04 +0000
commit741322a01a8d91f2082a2ba6fdb8b867bc227a26 (patch)
treebf009d0b7593f496d14b3cf0cdc80bd5cb581125 /test/threads.cxx
parente0a8bd61e7b658c71f4b7c0a71136b5d8535d6e4 (diff)
The threads demo would display negative prime numbers
on MacOS X; this appears to be a MacOS X bug, but we added a workaround to "fix" this (STR #1138) git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@4740 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'test/threads.cxx')
-rw-r--r--test/threads.cxx11
1 files changed, 10 insertions, 1 deletions
diff --git a/test/threads.cxx b/test/threads.cxx
index 7f9320a4d..b54a882ea 100644
--- a/test/threads.cxx
+++ b/test/threads.cxx
@@ -61,9 +61,10 @@ void* prime_func(void* p)
}
// very simple prime number calculator !
- for (; ; n+= step) {
+ for (;;) {
int p;
int hn = (int)sqrt((double)n);
+
for (p=3; p<=hn; p+=2) if ( n%p == 0 ) break;
if (p >= hn) {
char s[128];
@@ -72,8 +73,16 @@ void* prime_func(void* p)
browser->add(s);
browser->bottomline(browser->size());
if (n > value->value()) value->value(n);
+ n += step;
Fl::unlock();
Fl::awake((void*) (browser == browser1? p:0)); // Cause the browser to redraw ...
+ } else {
+ // This should not be necessary since "n" and "step" a local variables,
+ // however it appears that at least MacOS X has some threading issues
+ // that cause semi-random corruption of the (stack) variables.
+ Fl::lock();
+ n += step;
+ Fl::unlock();
}
}
return 0;