SWI-Prolog Threads Simple Example - multithreading

Can someone give a simple example of how to syncronize a multi-threaded prolog program.
I had gone through the manual but there are no examples to explain how to use.

Related

Multithreading in Embedded Systems

I am confused about the following:
I am hoping to get a job in the field of embedded systems. However, every interview I've had seems to end up with a conversation about threads in C and how to do thread-safe programming
My question is how do I go about learning multithreading in embedded systems? Are they the same as POSIX threads? For example, the tasks in FreeRTOS. Are they same thing as pthreads?
Can someone give me some tips on what to do and where to start?
Every OS has it's own threads/task/processes characteristics.
Despite the differences, the methods to synchronize, guard and interchange data between those, are roughly the same.
If someone knows that you don't know a specific OS, invited you to an interview - he/she probably expects you to answer in general and not to be OS specific.
You can solve any problem with POSIX (or any other) tool-set in mind and to mention that migration of the solution to a non-POSIX environment will keep same logic with some minor adaptations.
Multithreading concept is almost same everywhere, whether in RTOS or Linux.
The difference is in the operational behavior.
My question is how do I go about learning multithreading in embedded
systems?
My suggestion is to first learn and understand the concepts of multithreading by referring some online material, you can practice by writing some simple codes on your desktop running any flavor of Linux.
The go for some advanced topics like synchronization mechanism using Semaphore and Mutexes, you will then get to learn about the basic concept of when to use a semaphore and when to use a mutex for thread synchronization.
Then move to some Embedded Targets and try out some code using uCOS-II/uCOS-III or FreeRTOS.
Are they the same as POSIX threads?
No, they are not exactly same, POSIX thread library is a bit advance and is highly portable on different OS. For e.g. a multithread code written on Linux using pthread can also be compiled and executed on Windows with little or no change.
On the other hand, a thread implementation on RTOS is different, threads in RTOS are treated as tasks and they start executing only when a call to start the scheduler is made.
From my own experience trying to find learning resources, I found the the FreeRTOS docs very useful. They have both a reference manual as well as the Mastering the FreeRTOS Kernal doc which includes code snippets and covers topics such as task management, software timers, resource management, and general thread safe programming techniques. I dont think this would be the best place to start out, but once you've familiarized yourself with basics the other answers and comments have mentioned, this could help with the next step of learning by doing.

Linux Kernel Programming, how to get information?

I'm a newbie on Linux programming and I don't know exactly where I can get information of functions for example. There is a directory Documentations in my sources. But I can't find semaphore stuff there for example. Is there a documentation for all the function somewhere in the sources? Or not obligatorily?
The Linux Kernel Newbies site is a good point to start.
And, of course, the kernel itself is the best reference. To get started. Also have a look at kernel.org/doc. For semaphores, look at this page here.

Which of this program can be multithreaded?

I am a normal user and does not have strong background in programming.
I have a 64 bit, dual core machine (Dell Vostro 3400) and I think I can run multithreaded program with this machine (yes?)
The program that I think could be convert into multithreaded program is this:
http://code.google.com/p/malwarecookbook/source/browse/trunk/3/8/pescanner.py
Is possible to do so?
If yes, which part should being edited so that it will work?
Thanks.
Multithreading is not an easy subject.
I suggest you read up on some tutorials, see:
http://www.tutorialspoint.com/python/python_multithreading.htm
http://www.devshed.com/c/a/Python/Basic-Threading-in-Python/
http://www.artfulcode.net/articles/multi-threading-python/
To answer the general part of your question, you can run multithreaded code an any machine newer than say 2000.
Your question is too broad though to answer without going into details on the code.
My suggestion
I suggest you try the tutorials first and write same sample programs, ask a specific question with sourcecode! if you get stuck.
That's a road I'd recommend rather than taking someone else's code and rewriting it without detailed knowledge of threads.

There is a type named thread in lua. Does anyone know something of this?

I was reading the lua manual (looking for something) and I found out that there is a type named thread in lua. Of wath I read it represents independent threads of execution and it is used to implement coroutines.
Here is the link to the place I read it.
http://www.lua.org/manual/5.1/manual.html#2.2
How do I use these threads? Are there any good tutorials?
I have googled and had no luck.
I would advise you to look at the Co-routine tutorial and see if that is helpful for you.

Multithreaded Haskell

I'm learning Haskell and I'd like to write some multithreaded programs now to see the performance gains from that in a functional language. I can find some references to it on the internet but never a proper introduction to it. Can anyone point me to a guide which is understandable for someone who knows the syntax fairly well, but is not a wizard in Haskell?
I gave a 3 hour course on this topic at DEFUN 2009. The slides and code are online: Multicore Haskell Now!
Have you read Real Word Haskell?
http://book.realworldhaskell.org/read/concurrent-and-multicore-programming.html
I think the paper "A Tutorial on Parallel and Concurrent Programming in Haskell" is the perfect starting point for you. You can find it here:
http://research.microsoft.com/en-us/um/people/simonpj/papers/parallel/index.htm

Resources