Comments on: Looking for Linux C code...

Carl Sassenrath, CTO
REBOL Technologies
4-Feb-2009 4:10 GMT

Article #0172
Main page || Index || Prior Article [0171] || Next Article [0173] || 16 Comments || Send feedback

R3 needs a small amount of code to make its Linux release more usable.

Specifically, we are looking for implementations of:

  • CALL - Forks an external application. We're looking for something fairly short and simple. (Note we already have R2 code for this which we could use, but it's quite long and complex, dealing with redirection/pipes, etc., and we'd prefer something simpler.)
  • BROWSE - Opens the web browser to a given URL. This requires that we know what the default browser is on a Linux system. We need code to do that. We hope Linux has an official standard here now. (It didn't used to.)
  • EXPLORE - Opens a given folder at the Desktop level of Linux. (BTW, this name is not final, that's just what it's called on Win32.)
  • THREAD - Spawns a thread in Linux (with its own thread-local variable space).

We're not experts on more recent Linux architectural improvements, so if you know how to do any of the above, please let me know via RebDev, Feedback, or a comment here (I will review them every few days.)



Brian Hawley
5-Feb-2009 13:47:35
Here is a good model for the EXPLORE command - just change the CALL command:
explore: func [
    "Open directory in the file manager (shell shortcut function)."
    'path [file! word! path! string! unset!]
        "Accepts %file, :variables, and just words (as dirs)"
] [
    path: case [
        unset? :path [to-local-file what-dir]
        file? path [to-local-file path]
        string? path [path]
        true [to-local-file to-file path]
    call ajoin [{"} get-env "SystemRoot" {\explorer.exe" } mold path]

If there is a good way to be really specific about which shell command is called, that would help avoid spoofing.

5-Feb-2009 21:04:03
why concentrating "on more recent Linux architectural improvements"

is this what you mean? perhaps the old ways are the better ways people keep forgetting....but you know this better than anyone Carl

call: Calling an external program in C (Linux)

5-Feb-2009 21:30:53
it seems linux still doesnt have any concept of default browser so for "BROWSE" the still prefered simple option is to still throw up a dialog box asking which browser they'd like to use and store it somewere for later use.... or the hacky way , assume a default FF or some such...
5-Feb-2009 21:39:06
oc you might look at how xdg-open does it !


Bruno Albuquerque
6-Feb-2009 11:51:26
Hi Carl.

This is kind of a comment hijack (sorry for that), but I would like to ask what steps could I take if I wanted to port Rebol to a different platform? More specifically, I wanted to get it running under Haiku (it is basically BeOS but with a greater POSIX compatibility which would certainly help with the port).

6-Feb-2009 11:58:54
Bruno, we're waiting for the open host environment interface code to be released.
6-Feb-2009 15:46:16
My terrific Asus Eee netbook runs a Debian linux ( Xandros )

It comes with Firefox and Konqueror.

It has now displaced my iTouch as my web appliance ... our Rebol 276 DEB Core and View run fine on it ... I am hoping to be able to put a note up at eeeuser that Rebol 3 alpha is in a DEB pkg ; - )

7-Feb-2009 19:11:20
Btw, im also orienting from Apple hardware towards Asus Eee PC.. just because of the greatest battery life time (which is highly required by my life style).

Eee BUT definately with Linux!

Eee is a quickly growing community. It is a great opportunity to spread Rebol.

Andreas Bolka
8-Feb-2009 19:53:18
For BROWSE and EXPLORE, just CALL "xdg-open" with the URL or directory, respectively. That's part of the Portland project, and while it's not 100% portable across all distros, it's fairly well supported on all major distros (Debian, Fedora, etc).
9-Feb-2009 12:07:41
Please have a fallback if you use that function, or it won't work on many Linuxes.
15-Feb-2009 8:52:15
You should probably do it like XChat: FAQ entry explaining the method

It uses xdg-open, if available. The GNOME/KDE handlers else. If none of them work, you may still ask the user.

16-Feb-2009 7:17:01
That looks as good as it gets.
21-Feb-2009 5:42:39
You could call a user-shellscript which calls the browser. Most flexible.
23-Jun-2009 9:15:03
Gotta love that Firefox winning formula. See what Opera does...then do exactly that. For a moment I thought Firefox was innovating with its "awesome bar" and even read several books on this problem ( ) But upon inspection, I found that typing "awesome bar" in opera displays...this page.
5-Dec-2011 18:40:59

Linux uses POSIX Thread library. In short pthread. Also posix compatibility will make our implementation portable on windows and Mac too. I am a newbie to Rebol. Please bear with my syntax errors. From my limited knowledge of ur internals, I believe the access should be provided through by linking and building your core (C/C++) interpreter(boot strap) code for Linux or using RXI (slow and may be tricky).

Here is some good info on how to create and manage threads using pthreads: . Code Semantics may contains verbs as explained below:

make-thread iterations &threadParams [ ..code executed within thread.. ]

Threads are created using pthread_create and passed with the code within make-thread's block , &threadParams is optional if you do not want to pass any data to the wrapped code. Thread references should be hidden from user code and stored in an internal array. Iterations resolve to the number of threads to be created i.e. the number of times pthread_create is called. Internally, this is also the upper bound of the thread reference array, and a minimum value of 1 is mandatory (Any value lesser is illogical). The returned integer status can be used internally to throw an exception if thread creation/execution fails. The end of block will fire a pthread_join using the array of thread references, if the array size exceeds 1. We need to make threads wait using join only if there are more than 1 threads opened.

Sample code: param1: some_data param2: some_more_data

make-thread 3 :param1 :param2 [ some thread_local data ]

As for thread local data, pthreads supports it implicitly on code passed through the function. Please read this reference Any variable data within make-threads blocks will be thread local by default unless otherwise explicitly passed as a param to the block

Signals can fired as sleep msecs [] These verbs should be declarable only within a make-thread block but illegal within a LOCK to prevent deadlocks -- Need to brainstorm this one.

Sample code: make-thread 3 param1 param2 [ sleep 10 ]

Mutex support requires verbs for LOCK /TRYLOCK (Very very important, saves many a dead lock state from occuring). Refer pthread_mutex_lock, pthread_mutex_trylock and pthread_mutex_unlock

mutex_var: mutex lock :mutex_var [ ] try-lock :mutex_var [ ]

The end of block results in an unlock operation on the mutex. These verbs are valid only within a make-thread block while the mutex_var declaration should be outside the make-thread block. This is a never a thread local variable accessible to all. preferably set internally statically or as a CAS operation(refer below for CAS)

Sample code:

my_mutex: mutex //my mutex is variable reference (word) and is initialized internally using PTHREAD_MUTEX_INITIALIZER. param1: some_data param2: some_more_data

make-thread 3 :param1 :param2 [ lock :my_mutex [ :param1 do some eval ] ....]

5-Dec-2011 18:41:45

Ref is another semantic suitable for Rebol though not exposed in native pthreads. Lesser the number of mutexes the better (I am no fan of locks - the dreaded deadlock). Closes to it, I see is a Linux level mutex primitive called Futex(Userspace and use CAS), but this one is very tricky to get right since knowledge of generated assembler is assumed for proper use of this primitive.

Encouraging Atomic shared access is worth the effort by exposing CAS (Compare And Swap) is another issue to be brainstormed. A good verb for it is ATOMIC. Most modern processors have special instruction level support for this and is fast compared to mutexes.If we can sort out how to go below pthreads to access its CAS operations, then following expression is enough.

atomic_var: atomic

I have forcibly ignored Sempahores and Signals as they can be implemented at a later stage

Post a Comment:

You can post a comment here. Keep it on-topic.


Blog id:



 Note: HTML tags allowed for: b i u li ol ul font span div a p br pre tt blockquote

This is a technical blog related to the above topic. We reserve the right to remove comments that are off-topic, irrelevant links, advertisements, spams, personal attacks, politics, religion, etc.

Updated 15-Apr-2024 - Edit - Copyright REBOL Technologies -