[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Threads in Octave
From: |
Przemek Klosowski |
Subject: |
Threads in Octave |
Date: |
Mon, 26 Mar 2001 13:48:37 -0500 |
We ran into a strange problem with pthreads in octave, while trying to
implement an Octave GUI framework. After having weird synchronization
errors, we have whittled it down to a short test case. A standalone
program works as expected: a new thread is created and starts executing,
and the original thread is distinguishable from the new one; the following
source code:
#include <string>
#include <strstream>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <pthread.h>
void *
my_thread_process(void * null){
while (1){
cout << "testing\n";
sleep(1);
}
}
int
pthread_equal_rig( pthread_t t1, pthread_t t2) {
int result;
cout << "threads: " << (int) t1 << " " << (int) t2 ;
result = pthread_equal(t1,t2);
cout << " and the result is " << result << "\n";
return result;
}
int
main() {
pthread_t my_thread;
pthread_create(&my_thread, NULL, my_thread_process, NULL);
if(pthread_equal_rig(my_thread, pthread_self())) cout << "Same
threads!\n";
else cout << "Different
threads!\n";
}
when compiled with 'c++ -o test2 test2.c -lpthread' and run, outputs the
following:
% ./test2
threads: 1026 1024 and the result is 0
Different threads!
testing
The same code implemented as Octave extension (Octave 2.1.33) runs,
but the main process doesn't seem to return the correct thread ID from
pthread_self(). Furthermore, we seem to have problems with thread
synchronization (cut out from the above source), which we suspect are
caused by confusion within the thread system.
The output in this case is:
octave> test
threads: 1026 0 and the result is 1
Same threads!
So, it appears that pthreads_self() is returning 0 instead of the
thread ID for the parent (octave) process. The source code in this
case is almost exactly the same as the standalone code (see below)
So, did anyone play with Posix threads in Octave? Is our problem due
to a conflict between pthreads and octave, or are we doing something
wrong?
przemek klosowski, Ph.D. <address@hidden> (301)
975-6249
NIST Center for Neutron Research (bldg. 235), E111
National Institute of Standards and Technology
Gaithersburg, MD 20899, USA
.. and for spam extractors, FCC Commisioners' email is:
address@hidden,address@hidden,address@hidden,address@hidden
FTCtort: 202-326-2456 FTCIG: 202-326-2800 CybTip
800-843-5678
#include <octave/config.h>
#include <octave/oct-obj.h>
#include <octave/parse.h>
#include <octave/defun-dld.h>
#include <octave/error.h>
#include <octave/variables.h>
#include <octave/sighandlers.h>
#include <octave/mx-base.h>
#include <string>
#include <strstream>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <pthread.h>
#define TRUE 1
#define FALSE 0
void *
my_thread_process(void * null){
while (1){
cout << "testing\n";
sleep(1);
}
}
int
pthread_equal_rig( pthread_t t1, pthread_t t2) {
int result;
cout << "threads: " << (int) t1 << " " << (int) t2 ;
result = pthread_equal(t1,t2);
cout << " and the result is " << result << "\n";
return result;
}
DEFUN_DLD (test, args,, "test")
{
octave_value_list ret;
pthread_t my_thread;
pthread_create(&my_thread, NULL, my_thread_process, NULL);
if(pthread_equal_rig(my_thread, pthread_self())) printf("Same
threads!\n");
else
printf("Different threads!\n");
return ret;
}
-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.octave.org
How to fund new projects: http://www.octave.org/funding.html
Subscription information: http://www.octave.org/archive.html
-------------------------------------------------------------
- Threads in Octave,
Przemek Klosowski <=