Git Product home page Git Product logo

monetdbe-examples's People

Contributors

aris-koning avatar bernardom29 avatar giuliafrasca avatar hunhoffe avatar mitchellweg avatar njnes avatar sstalin avatar thzois avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

monetdbe-examples's Issues

Example typos

At cache.c example:

monetdbe_query(remote, "call sys.describe("sys","lineitem"", &schema);

There's a closing parenthesis missing,

Missing monetdbe_listen() in monetdbe.h

In the myserver.c there is a call to monetdbe_listen(). However the monetdbe_listen() is not defined in monetdbe.h.

Further, there is a call to monetdb_error(). I guess that should be monetdbe_error()...

Accessing remote monetdb

I am trying to access a monetdb-server on another machine in order to initiate a local embedded database with some initial values (C/C++).

However, the cache.c example accessing a remote database seems not to be up to date w.r.t the interface.

E.g. in

monetdbe_open(&remote, "monetdb://localhost:5000/sf1?user=monetdb&password=monetdb");

clearly a NULL is missing in the monetdbe_open(..., NULL) for the Option. However, adding the missing NULL does not seems to make the example work w.r.t be able to connect to the remote database.

Digging into the monetdbe.c, it seems to me like in order to force the monetdbe_open() to try to connect to a remote database, the remote-structure in the Option-structure needs to be filled in.

It would be of great help if you please could update the cache.c example and/or clarify how to connect to a remote named database.

If the option + remote struct has to be used: The remote struct seems to only have variable names for host, port, username, pw and language. How do one enter the database name ("sf1" in the cache-example or "demo" in the example below)?

To be specific, in the full monetdb-version we have e.g:
dbh = mapi_connect("192.168.1.21", 50000, "monetdb", "monetdb", "sql", "demo");

How would the equivalent monetdbe look like?

Issues building monetDB Oct2020-SP3 from source

I was trying to build monetDB Oct2020-SP from source on a RPi4B+ with Ubuntu 20.04 LTS, 64 bit.
The procedure I used to follow, which have worked on all versions previous to Oct2020, was:

export MonetDB_rel=Oct2020-SP3
export MonetDB_ver=11.39.13
export MonetDB_base_dir=$HOME/MonetDB-$MonetDB_rel
export MonetDB_source_dir=$MonetDB_base_dir/MonetDB-$MonetDB_ver
export MonetDB_build_dir=$MonetDB_base_dir/BUILD
export MonetDB_prefix_dir=$MonetDB_base_dir
mkdir $MonetDB_base_dir
cd $MonetDB_base_dir

wget https://dev.monetdb.org/downloads/sources/$MonetDB_rel/MonetDB-11.39.13.tar.xz
tar xf MonetDB-$MonetDB_ver.tar.xz
mkdir $MonetDB_build_dir
cd $MonetDB_build_dir

$MonetDB_source_dir/configure --prefix=$MonetDB_prefix_dir

However the last line results in the error:

-bash: /home/ubuntu/MonetDB-Oct2020-SP3/MonetDB-11.39.13/configure: No such file or directory

It seems like the build process is changed (https://www.monetdb.org/blog/from_automake_to_cmake), but without an updated doc (https://www.monetdb.org/Developers/SourceCompile).

To me it seems like the following is ok (after sudo apt install cmake bison):

export MonetDB_rel=Oct2020-SP3
export MonetDB_ver=11.39.13
export MonetDB_base_dir=$HOME/MonetDB-$MonetDB_rel
export MonetDB_source_dir=$MonetDB_base_dir/MonetDB-$MonetDB_ver
export MonetDB_prefix_dir=$MonetDB_base_dir

mkdir $MonetDB_base_dir
cd $MonetDB_base_dir

wget https://dev.monetdb.org/downloads/sources/$MonetDB_rel/MonetDB-11.39.13.tar.xz

tar xf MonetDB-$MonetDB_ver.tar.xz

cd $MonetDB_source_dir
mkdir build && cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
cmake --build .  --parallel -j 4

However, how do one install the compiled version? The old one had e.g.

make -j4 install

Is the one below the right one to use?

sudo cmake --build . --target install --config Release --parallel -j 4

extend monetdbe_bind

The current monetdbe_bind requires the input data too match the parameter /argument of the query. For decimal types the physical type could be any integer (bte,sht,int,lng,hge) with a scale. This is however hard too guess. So we probably need a more flexible interface, including the passed type to monetdbe_bind. That however requires conversion (sometimes)

Error when building from scratch on a 32 bit system

Tried to build the C-code on a 32bit RPi 4B, Bullseye, 4GB ram.
Latest version pr 11-aug-2023 (git clone https://github.com/MonetDB/MonetDB MonetDBe)
FYI: It builds without errors on 64 bit RPi 4B, Bullseye 8GB ram.

cmake --build .
Scanning dependencies of target moptions
[ 0%] Building C object common/options/CMakeFiles/moptions.dir/monet_options.c.o
[ 0%] Linking C static library libmoptions.a
[ 0%] Built target moptions
Scanning dependencies of target stream
[ 1%] Building C object common/stream/CMakeFiles/stream.dir/stream.c.o
In file included from /home/pi/MonetDBe/common/stream/stream_internal.h:19,
from /home/pi/MonetDBe/common/stream/stream.c:58:
/home/pi/MonetDBe/common/utils/matomic.h:90:2: error: #error "we need _Atomic(unsigned long long) to be lock free"
90 | #error "we need _Atomic(unsigned long long) to be lock free"

gmake[2]: *** [common/stream/CMakeFiles/stream.dir/build.make:82: common/stream/CMakeFiles/stream.dir/stream.c.o] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:2509: common/stream/CMakeFiles/stream.dir/all] Error 2
gmake: *** [Makefile:182: all] Error 2

matomic.h:

#if SIZEOF_LONG_LONG == 8
#if ATOMIC_LLONG_LOCK_FREE != 2
#error "we need _Atomic(unsigned long long) to be lock free"
#endif
typedef volatile atomic_ullong ATOMIC_TYPE;
typedef unsigned long long ATOMIC_BASE_TYPE;
#elif SIZEOF_LONG == 8
#if ATOMIC_LONG_LOCK_FREE != 2
#error "we need _Atomic(unsigned long) to be lock free"
#endif
typedef volatile atomic_ulong ATOMIC_TYPE;
typedef unsigned long ATOMIC_BASE_TYPE;
#else
#error "we need a 64 bit atomic type"
#endif

Other build info:

cmake -DCMAKE_BUILD_TYPE=Release ..
-- The C compiler identification is GNU 10.2.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Check if the system is big endian
-- Searching 16 bit integer
-- Looking for sys/types.h
-- Looking for sys/types.h - found
-- Looking for stdint.h
-- Looking for stdint.h - found
-- Looking for stddef.h
-- Looking for stddef.h - found
-- Check size of unsigned short
-- Check size of unsigned short - done
-- Searching 16 bit integer - Using unsigned short
-- Check if the system is big endian - little endian
-- Found BISON: /usr/bin/bison (found version "3.7.5")
-- Performing Test Iconv_IS_BUILT_IN
-- Performing Test Iconv_IS_BUILT_IN - Success
-- Found Iconv: /usr/lib/arm-linux-gnueabihf/libc.so
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Found Python3: /usr/bin/python3.9 (found version "3.9.2") found components: Interpreter Development NumPy Development.Module Development.Embed
-- Could NOT find LibLZMA (missing: LIBLZMA_LIBRARY LIBLZMA_INCLUDE_DIR LIBLZMA_HAS_AUTO_DECODER LIBLZMA_HAS_EASY_ENCODER LIBLZMA_HAS_LZMA_PRESET)
-- Could NOT find LibXml2 (missing: LIBXML2_LIBRARY LIBXML2_INCLUDE_DIR)
-- Found PCRE: /usr/lib/arm-linux-gnueabihf/libpcre.so
-- Could NOT find BZip2 (missing: BZIP2_LIBRARIES BZIP2_INCLUDE_DIR)
-- Found CURL: /usr/lib/arm-linux-gnueabihf/libcurl.so (found version "7.74.0")
-- Found ZLIB: /usr/lib/arm-linux-gnueabihf/libz.so (found version "1.2.11")
-- Could NOT find LZ4 (missing: LZ4_LIBRARIES LZ4_INCLUDE_DIR) (Required is at least version "1.8.0")
-- Could NOT find Proj (missing: PROJ_LIBRARIES PROJ_INCLUDE_DIR)
-- Could NOT find Snappy (missing: SNAPPY_LIBRARIES SNAPPY_INCLUDE_DIR)
-- Could NOT find Valgrind (missing: VALGRIND_LIBRARIES VALGRIND_INCLUDE_DIR)
-- Could NOT find Readline (missing: READLINE_LIBRARIES READLINE_INCLUDE_DIR)
-- Could NOT find CFitsIO (missing: CFITSIO_LIBRARIES CFITSIO_INCLUDE_DIR)
-- Could NOT find NetCDF (missing: NETCDF_LIBRARIES NETCDF_INCLUDE_DIR)
-- Could NOT find KVM (missing: KVM_LIBRARIES KVM_INCLUDE_DIR)
-- Could NOT find Geos (missing: GEOS_LIBRARIES GEOS_INCLUDE_DIR)
-- Disable SHP, geom module required for ESRI Shapefile vault
-- Could NOT find ODBC (missing: ODBC_LIBRARY ODBC_INCLUDE_DIR)
-- Could NOT find ODBCinst (missing: ODBCINST_LIBRARIES ODBCINST_INCLUDE_DIR)
-- Could not find libR shared library.
-- Could NOT find LibR (missing: LIBR_HOME LIBR_EXECUTABLE LIBR_INCLUDE_DIRS LIBR_LIBRARIES LIBR_DOC_DIR)
-- Could NOT find Sphinx (missing: SPHINX_EXECUTABLE)
-- Could NOT find Createrepo (missing: CREATEREPO_EXECUTABLE)
-- Could NOT find Rpmbuild (missing: RPMBUILD_EXECUTABLE)
-- Found DpkgBuildpackage: /usr/bin/dpkg-buildpackage
-- Could NOT find Reprepro (missing: REPREPRO_EXECUTABLE)
-- Could NOT find Semodule (missing: SELINUX_MAKEFILE)
-- Found Awk: /usr/bin/awk
-- Could NOT find Candle (missing: CANDLE_EXECUTABLE)
-- Performing Test Werrorimplicitfunctiondeclaration_FOUND
-- Performing Test Werrorimplicitfunctiondeclaration_FOUND - Success
-- Performing Test Wpointerarith_FOUND
-- Performing Test Wpointerarith_FOUND - Success
-- Performing Test Wundef_FOUND
-- Performing Test Wundef_FOUND - Success
-- Performing Test Wformat2_FOUND
-- Performing Test Wformat2_FOUND - Success
-- Performing Test Wformatoverflow1_FOUND
-- Performing Test Wformatoverflow1_FOUND - Success
-- Performing Test Wnoformatnonliteral_FOUND
-- Performing Test Wnoformatnonliteral_FOUND - Success
-- Performing Test Wnocastfunctiontype_FOUND
-- Performing Test Wnocastfunctiontype_FOUND - Success
-- Performing Test Winitself_FOUND
-- Performing Test Winitself_FOUND - Success
-- Performing Test Winvalidpch_FOUND
-- Performing Test Winvalidpch_FOUND - Success
-- Performing Test Wmissingdeclarations_FOUND
-- Performing Test Wmissingdeclarations_FOUND - Success
-- Performing Test Wmissingformatattribute_FOUND
-- Performing Test Wmissingformatattribute_FOUND - Success
-- Performing Test Wmissingprototypes_FOUND
-- Performing Test Wmissingprototypes_FOUND - Success
-- Performing Test Wnomissingbraces_FOUND
-- Performing Test Wnomissingbraces_FOUND - Success
-- Performing Test Wnomissingfieldinitializers_FOUND
-- Performing Test Wnomissingfieldinitializers_FOUND - Success
-- Performing Test Woldstyledefinition_FOUND
-- Performing Test Woldstyledefinition_FOUND - Success
-- Performing Test Wpacked_FOUND
-- Performing Test Wpacked_FOUND - Success
-- Performing Test Wunknownpragmas_FOUND
-- Performing Test Wunknownpragmas_FOUND - Success
-- Performing Test Wvariadicmacros_FOUND
-- Performing Test Wvariadicmacros_FOUND - Success
-- Performing Test Wstackprotector_FOUND
-- Performing Test Wstackprotector_FOUND - Success
-- Performing Test fstackprotectorall_FOUND
-- Performing Test fstackprotectorall_FOUND - Success
-- Performing Test Wpackedbitfieldcompat_FOUND
-- Performing Test Wpackedbitfieldcompat_FOUND - Success
-- Performing Test Wsyncnand_FOUND
-- Performing Test Wsyncnand_FOUND - Success
-- Performing Test Wjumpmissesinit_FOUND
-- Performing Test Wjumpmissesinit_FOUND - Success
-- Performing Test Wmissingincludedirs_FOUND
-- Performing Test Wmissingincludedirs_FOUND - Success
-- Performing Test Wlogicalop_FOUND
-- Performing Test Wlogicalop_FOUND - Success
-- Performing Test Wduplicatedcond_FOUND
-- Performing Test Wduplicatedcond_FOUND - Success
-- Performing Test Wduplicatedbranches_FOUND
-- Performing Test Wduplicatedbranches_FOUND - Success
-- Performing Test Wrestrict_FOUND
-- Performing Test Wrestrict_FOUND - Success
-- Performing Test Wnestedexterns_FOUND
-- Performing Test Wnestedexterns_FOUND - Success
-- Performing Test Wmissingnoreturn_FOUND
-- Performing Test Wmissingnoreturn_FOUND - Success
-- Performing Test Wuninitialized_FOUND
-- Performing Test Wuninitialized_FOUND - Success
-- Performing Test Wnocharsubscripts_FOUND
-- Performing Test Wnocharsubscripts_FOUND - Success
-- Performing Test Wunreachablecode_FOUND
-- Performing Test Wunreachablecode_FOUND - Success
-- Performing Test Wnounreachablecode_FOUND
-- Performing Test Wnounreachablecode_FOUND - Success
-- Looking for dispatch/dispatch.h
-- Looking for dispatch/dispatch.h - not found
-- Looking for dlfcn.h
-- Looking for dlfcn.h - found
-- Looking for fcntl.h
-- Looking for fcntl.h - found
-- Looking for io.h
-- Looking for io.h - not found
-- Looking for kvm.h
-- Looking for kvm.h - not found
-- Looking for libgen.h
-- Looking for libgen.h - found
-- Looking for libintl.h
-- Looking for libintl.h - found
-- Looking for mach/mach_init.h
-- Looking for mach/mach_init.h - not found
-- Looking for mach/task.h
-- Looking for mach/task.h - not found
-- Looking for mach-o/dyld.h
-- Looking for mach-o/dyld.h - not found
-- Looking for netinet/in.h
-- Looking for netinet/in.h - found
-- Looking for poll.h
-- Looking for poll.h - found
-- Looking for procfs.h
-- Looking for procfs.h - not found
-- Looking for pwd.h
-- Looking for pwd.h - found
-- Looking for semaphore.h
-- Looking for semaphore.h - found
-- Looking for stdatomic.h
-- Looking for stdatomic.h - found
-- Looking for strings.h
-- Looking for strings.h - found
-- Looking for stropts.h
-- Looking for stropts.h - not found
-- Looking for sys/file.h
-- Looking for sys/file.h - found
-- Looking for sys/ioctl.h
-- Looking for sys/ioctl.h - found
-- Looking for sys/mman.h
-- Looking for sys/mman.h - found
-- Looking for sys/param.h
-- Looking for sys/param.h - found
-- Looking for include files stdlib.h, sys/random.h
-- Looking for include files stdlib.h, sys/random.h - found
-- Looking for sys/resource.h
-- Looking for sys/resource.h - found
-- Looking for sys/stat.h
-- Looking for sys/stat.h - found
-- Looking for sys/sysctl.h
-- Looking for sys/sysctl.h - found
-- Looking for sys/termios.h
-- Looking for sys/termios.h - found
-- Looking for sys/times.h
-- Looking for sys/times.h - found
-- Looking for sys/uio.h
-- Looking for sys/uio.h - found
-- Looking for sys/un.h
-- Looking for sys/un.h - found
-- Looking for sys/wait.h
-- Looking for sys/wait.h - found
-- Looking for unistd.h
-- Looking for unistd.h - found
-- Looking for winsock2.h
-- Looking for winsock2.h - not found
-- Looking for opendir
-- Looking for opendir - found
-- Looking for gethostbyname
-- Looking for gethostbyname - found
-- Looking for setsockopt
-- Looking for setsockopt - found
-- Looking for gettimeofday
-- Looking for gettimeofday - found
-- Looking for getaddrinfo
-- Looking for getaddrinfo - found
-- Looking for getaddrinfo
-- Looking for getaddrinfo - not found
-- Looking for fdatasync
-- Looking for fdatasync - found
-- Looking for accept4
-- Looking for accept4 - found
-- Looking for asctime_r
-- Looking for asctime_r - found
-- Looking for clock_gettime
-- Looking for clock_gettime - found
-- Looking for ctime_r
-- Looking for ctime_r - found
-- Looking for dispatch_semaphore_create
-- Looking for dispatch_semaphore_create - not found
-- Looking for fallocate
-- Looking for fallocate - found
-- Looking for fcntl
-- Looking for fcntl - found
-- Looking for fork
-- Looking for fork - found
-- Looking for fsync
-- Looking for fsync - found
-- Looking for ftime
-- Looking for ftime - found
-- Looking for getentropy
-- Looking for getentropy - found
-- Looking for getexecname
-- Looking for getexecname - not found
-- Looking for getlogin
-- Looking for getlogin - found
-- Looking for getopt_long
-- Looking for getopt_long - found
-- Looking for getrlimit
-- Looking for getrlimit - found
-- Looking for gettimeofday
-- Looking for gettimeofday - found
-- Looking for getuid
-- Looking for getuid - found
-- Looking for gmtime_r
-- Looking for gmtime_r - found
-- Looking for localtime_r
-- Looking for localtime_r - found
-- Looking for strerror_r
-- Looking for strerror_r - found
-- Looking for lockf
-- Looking for lockf - found
-- Looking for madvise
-- Looking for madvise - found
-- Looking for mremap
-- Looking for mremap - found
-- Looking for nanosleep
-- Looking for nanosleep - found
-- Looking for nl_langinfo
-- Looking for nl_langinfo - found
-- Looking for _NSGetExecutablePath
-- Looking for _NSGetExecutablePath - not found
-- Looking for pipe2
-- Looking for pipe2 - found
-- Looking for poll
-- Looking for poll - found
-- Looking for popen
-- Looking for popen - found
-- Looking for posix_fadvise
-- Looking for posix_fadvise - found
-- Looking for posix_fallocate
-- Looking for posix_fallocate - found
-- Looking for posix_madvise
-- Looking for posix_madvise - found
-- Looking for putenv
-- Looking for putenv - found
-- Looking for setsid
-- Looking for setsid - found
-- Looking for shutdown
-- Looking for shutdown - found
-- Looking for sigaction
-- Looking for sigaction - found
-- Looking for stpcpy
-- Looking for stpcpy - found
-- Looking for strcasestr
-- Looking for strcasestr - found
-- Looking for strncasecmp
-- Looking for strncasecmp - found
-- Looking for strptime
-- Looking for strptime - found
-- Looking for strsignal
-- Looking for strsignal - found
-- Looking for sysconf
-- Looking for sysconf - found
-- Looking for task_info
-- Looking for task_info - not found
-- Looking for times
-- Looking for times - found
-- Looking for uname
-- Looking for uname - found
-- Looking for semtimedop
-- Looking for semtimedop - found
-- Looking for pthread_kill
-- Looking for pthread_kill - found
-- Looking for pthread_sigmask
-- Looking for pthread_sigmask - found
-- Looking for regcomp
-- Looking for regcomp - found
-- Check size of size_t
-- Check size of size_t - done
-- Check size of ssize_t
-- Check size of ssize_t - done
-- Check size of char
-- Check size of char - done
-- Check size of short
-- Check size of short - done
-- Check size of int
-- Check size of int - done
-- Check size of long
-- Check size of long - done
-- Check size of long long
-- Check size of long long - done
-- Check size of double
-- Check size of double - done
-- Check size of wchar_t
-- Check size of wchar_t - done
-- Check size of socklen_t
-- Check size of socklen_t - done
-- Check size of __int128
-- Check size of __int128 - failed
-- Check size of __int128_t
-- Check size of __int128_t - failed
-- Check size of __uint128_t
-- Check size of __uint128_t - failed
-- 128-bit integers not supported by this compiler
-- Check if the system is big endian
-- Searching 16 bit integer
-- Searching 16 bit integer - Using unsigned short
-- Check if the system is big endian - little endian
-- Configuring done
-- Generating done
-- Build files have been written to: /home/pi/MonetDBe/build

Error using monetdbe_open() with persistency

The examples indicates that in monetdbe_open() the second argument is a string for the db directory or NULL for in-memory mode.

The following inmemory works ok:

monetdbe_database db = NULL;
monetdbe_open(&db, NULL /* inmemory database /, NULL / no options */);

However, this one (and any variants) fails:

monetdbe_open(&db, "mydbdir/", NULL /* no options */);

Is there an example of how to open a db with persistency, or is it a bug?

Is monetdbe threadsafe?

I am testing MonetDBe in a multi threaded application (C++/Linux), where some threads insert data into the database and other threads read.

In your blog about MonetDBe you claim that MonetDBe is thread safe. However, for the time being it seems to me that I have to protect the database access by using a mutex to avoid segfault (testing with in-memory database, i.e no persistence).

Do you have any thoughts about that? Are there any implementation guidelines to follow for using MonetDBe in a threaded application where different threads access the in-memory database? I am using a global variabel monetdbe_database _db referencing the opened in-memory database (and hence accessible for all threads).

A sort of pseudo code (sorry about the messy formatting):

`
monetdbe_database _dbe = NULL;
mutex monetdbeMutex;
bool _sysRunning = false;

int monetDBeCreateDB(){
	monetdbe_options dbOptions;
	dbOptions.memorylimit    = 1000;
	dbOptions.querytimeout   = 60;
	dbOptions.sessiontimeout = 60; 
	dbOptions.nr_threads     = 4;

	char *msg= NULL;

	int statusDB = monetdbe_open(&_dbe, NULL /*pathDB*/, &dbOptions);
	if (statusDB < 0){
		return statusDB;
	} 

	msg = monetdbe_query(_dbe, "CREATE TABLE table0 (t bigint, x0 double, x1 double, x2 double, x3 double, x4 double, x5 double, x6 double);", NULL, NULL);
	if (msg != NULL) printf("%s\n", msg);

	msg = monetdbe_query(_dbe, "CREATE TABLE table1 (t bigint, y0 double, y1 double, y2 double, y3 double);", NULL, NULL);
	if (msg != NULL) printf("%s\n", msg);

	msg = monetdbe_query(_dbe, "CREATE TABLE table2   (t bigint, y0 double, y1 double, y2 double, y3 double);", NULL, NULL);
	if (msg != NULL) printf("%s\n", msg);

	msg = monetdbe_query(_dbe, "CREATE TABLE table3    (t bigint, u0 double, u1 double, u2 double, u3 double, u4 double);", NULL, NULL);
	if (msg != NULL) printf("%s\n", msg);

	return statusDB;
}

void thread0(){
  
   char* msg = NULL;
   monetdbe_result *result;

   while (_sysRunning){
		this_thread::sleep_for(chrono::milliseconds(10000));
    	if (_dbe != NULL){
		    monetdbeMutex.lock();
		    msg = monetdbe_query(_dbe, "SELECT sys.epoch(t) as t_utc,* FROM table0 order by t desc limit 10;", &result, NULL);
			monetdbeMutex.unlock();

			if ( msg == NULL) {
				//do something with the data

			}

		    monetdbeMutex.lock();
			monetdbe_cleanup_result(_dbe, result);
			monetdbeMutex.unlock();
		}
	}
}

void thread1(){
  
   char* msg = NULL;
   string dbQueryStr;
   int64_t rows_affected;  

   while (_sysRunning){
        this_thread::sleep_for(chrono::milliseconds(1000));
    	if (_dbe != NULL){
			dbQueryStr  = "INSERT INTO table0 (t,x0,x1,x2,x3,x4,x5,x6) VALUES (" ... some values ... ");"; 	
			dbQueryStr += "INSERT INTO table1 (t,y0,y1,y2,y3) VALUES ("        ... som values ... ");"; 	            	
			dbQueryStr += "INSERT INTO table2 (t,u0,u1,u2,u3,u4) VALUES ("      ... some values ... ");"; 	            	
			dbQueryStr += "INSERT INTO table3 (t,y0,y1,y2,y3) VALUES (" ... some values ... ");"; 	   

			monetdbeMutex.lock();
			msg = monetdbe_query(_dbe, (char *)dbQueryStr.c_str(), NULL, &rows_affected); 
			monetdbeMutex.unlock();

			if (msg != NULL) {
	                        printf("%s\n",dbQueryStr.c_str());
				printf("%s\n", msg);
			}
    	}
    } //while
}


int main(int argc, char **ppArgv){

	if (monetDBeCreateDB() >= 0){
		_sysRunning = true;     //must be set false by e.g. a sighandler to stop the application
		threads.push_back(std::thread(thread0)); 
		threads.push_back(std::thread(thread1)); 
	}

 	while (_sysRunning){
		this_thread::sleep_for(chrono::milliseconds(60000));
 	}
        if (_dbe != NULL){
             monetdbe_close(_dbe);
            _dbe = NULL;
          }
}

`

In the code like above, if the mutex protection are removed, the application segfaults after a while.

Tested on RPi4B, g++.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.