summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES3
-rw-r--r--test/threads.cxx11
-rw-r--r--test/threads.h5
3 files changed, 15 insertions, 4 deletions
diff --git a/CHANGES b/CHANGES
index 1241beb3f..11d31bf1b 100644
--- a/CHANGES
+++ b/CHANGES
@@ -3,6 +3,9 @@ CHANGES IN FLTK 1.1.7
- Documentation fixes (STR #571, STR #648, STR #692, STR
#730, STR #744, STR #745, STR #931, STR #942, STR #960,
STR #969)
+ - 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)
- Fl::dnd() now sets the content type of the drag to
"text/uri-list" when it sees the dragged text is
composed of URIs.
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;
diff --git a/test/threads.h b/test/threads.h
index 8d376b147..aa89e7bea 100644
--- a/test/threads.h
+++ b/test/threads.h
@@ -50,9 +50,8 @@
typedef pthread_t Fl_Thread;
-static int fl_create_thread(Fl_Thread& t, void *(*f) (void *), void* p)
-{
- return pthread_create((pthread_t*)&t, 0, f, p);
+static int fl_create_thread(Fl_Thread& t, void *(*f) (void *), void* p) {
+ return pthread_create((pthread_t*)&t, &attr, f, p);
}
# elif defined(WIN32) && !defined(__WATCOMC__) // Use Windows threading...