<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="FeedCreator 1.8" -->
<?xml-stylesheet href="https://medjava.ro/lib/exe/css.php?s=feed" type="text/css"?>
<rdf:RDF
    xmlns="http://purl.org/rss/1.0/"
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
    xmlns:dc="http://purl.org/dc/elements/1.1/">
    <channel rdf:about="https://medjava.ro/feed.php">
        <title>Med Java - c:pthreads</title>
        <description></description>
        <link>https://medjava.ro/</link>
        <image rdf:resource="https://medjava.ro/lib/exe/fetch.php?media=wiki:dokuwiki.svg" />
       <dc:date>2026-04-08T07:44:33+00:00</dc:date>
        <items>
            <rdf:Seq>
                <rdf:li rdf:resource="https://medjava.ro/doku.php?id=c:pthreads:barrier-odd-even-transposition-sort&amp;rev=1735842138&amp;do=diff"/>
                <rdf:li rdf:resource="https://medjava.ro/doku.php?id=c:pthreads:barrier-shear-sort-parallel&amp;rev=1735842138&amp;do=diff"/>
                <rdf:li rdf:resource="https://medjava.ro/doku.php?id=c:pthreads:barrier-simulate-work&amp;rev=1735842138&amp;do=diff"/>
                <rdf:li rdf:resource="https://medjava.ro/doku.php?id=c:pthreads:binary-search-parallel&amp;rev=1735842138&amp;do=diff"/>
                <rdf:li rdf:resource="https://medjava.ro/doku.php?id=c:pthreads:hello-world&amp;rev=1735842138&amp;do=diff"/>
                <rdf:li rdf:resource="https://medjava.ro/doku.php?id=c:pthreads:makefile&amp;rev=1735842138&amp;do=diff"/>
                <rdf:li rdf:resource="https://medjava.ro/doku.php?id=c:pthreads:merge-sort-parallel&amp;rev=1735842138&amp;do=diff"/>
                <rdf:li rdf:resource="https://medjava.ro/doku.php?id=c:pthreads:mutex-barrier-array-sum&amp;rev=1735842138&amp;do=diff"/>
                <rdf:li rdf:resource="https://medjava.ro/doku.php?id=c:pthreads:mutex-shared-variable&amp;rev=1735842138&amp;do=diff"/>
                <rdf:li rdf:resource="https://medjava.ro/doku.php?id=c:pthreads:parallel-increment-vector&amp;rev=1735842138&amp;do=diff"/>
            </rdf:Seq>
        </items>
    </channel>
    <image rdf:about="https://medjava.ro/lib/exe/fetch.php?media=wiki:dokuwiki.svg">
        <title>Med Java</title>
        <link>https://medjava.ro/</link>
        <url>https://medjava.ro/lib/exe/fetch.php?media=wiki:dokuwiki.svg</url>
    </image>
    <item rdf:about="https://medjava.ro/doku.php?id=c:pthreads:barrier-odd-even-transposition-sort&amp;rev=1735842138&amp;do=diff">
        <dc:format>text/html</dc:format>
        <dc:date>2025-01-02T18:22:18+00:00</dc:date>
        <dc:creator>Anonymous (anonymous@undisclosed.example.com)</dc:creator>
        <title>barrier-odd-even-transposition-sort</title>
        <link>https://medjava.ro/doku.php?id=c:pthreads:barrier-odd-even-transposition-sort&amp;rev=1735842138&amp;do=diff</link>
        <description>Odd Even Transposition Sort (Parallel Bubble Sort) Using Pthreads and Barrier


#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;pthread.h&gt;

#define NUM_THREADS 4  // Number of threads (should be even)
#define ARRAY_SIZE 8   // Size of the array

int array[ARRAY_SIZE];
pthread_barrier_t barrier;

// Function to swap two array elements
void swap(int *a, int *b) {
    int temp = *a;
    *a = *b;
    *b = temp;
}

// Function executed by each thread
void *sort(void *arg) {
    int thread_part = *(i…</description>
    </item>
    <item rdf:about="https://medjava.ro/doku.php?id=c:pthreads:barrier-shear-sort-parallel&amp;rev=1735842138&amp;do=diff">
        <dc:format>text/html</dc:format>
        <dc:date>2025-01-02T18:22:18+00:00</dc:date>
        <dc:creator>Anonymous (anonymous@undisclosed.example.com)</dc:creator>
        <title>barrier-shear-sort-parallel</title>
        <link>https://medjava.ro/doku.php?id=c:pthreads:barrier-shear-sort-parallel&amp;rev=1735842138&amp;do=diff</link>
        <description>Shear Sort Using Pthreads and Barrier


#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;unistd.h&gt;
#include &lt;pthread.h&gt;

#define MATRIX_SIZE 4  // Size of the matrix (example 4x4)
#define NUM_THREADS (MATRIX_SIZE * 2)  // Number of threads for matrix&#039;s rows and columns

int matrix[MATRIX_SIZE][MATRIX_SIZE];
pthread_barrier_t barrier;

// Function to swap two elements
void swap(int *a, int *b) {
    int temp = *a;
    *a = *b;
    *b = temp;
}

// Function executed by each thread to sort a row or…</description>
    </item>
    <item rdf:about="https://medjava.ro/doku.php?id=c:pthreads:barrier-simulate-work&amp;rev=1735842138&amp;do=diff">
        <dc:format>text/html</dc:format>
        <dc:date>2025-01-02T18:22:18+00:00</dc:date>
        <dc:creator>Anonymous (anonymous@undisclosed.example.com)</dc:creator>
        <title>barrier-simulate-work</title>
        <link>https://medjava.ro/doku.php?id=c:pthreads:barrier-simulate-work&amp;rev=1735842138&amp;do=diff</link>
        <description>Pthread barrier example - simulate work then wait at barrier


#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;unistd.h&gt;
#include &lt;pthread.h&gt;

#define NUM_THREADS 5  // Number of threads

// Barrier variable
pthread_barrier_t barrier;

// Function executed by each thread
void *thread_work(void *tid) {
    long my_tid = (long)tid;
    printf(&quot;Thread %ld is doing some work before the barrier\n&quot;, my_tid);

    // Simulate some work
    sleep(1); // Sleep for a second to simulate work

    // Wait …</description>
    </item>
    <item rdf:about="https://medjava.ro/doku.php?id=c:pthreads:binary-search-parallel&amp;rev=1735842138&amp;do=diff">
        <dc:format>text/html</dc:format>
        <dc:date>2025-01-02T18:22:18+00:00</dc:date>
        <dc:creator>Anonymous (anonymous@undisclosed.example.com)</dc:creator>
        <title>binary-search-parallel</title>
        <link>https://medjava.ro/doku.php?id=c:pthreads:binary-search-parallel&amp;rev=1735842138&amp;do=diff</link>
        <description>Parallel Binary Search Using Pthreads


#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;pthread.h&gt;

#define ARRAY_SIZE 16  // Size of the array
#define NUM_THREADS 4  // Number of threads
#define TARGET 7       // Number to search for

int array[ARRAY_SIZE];
int found = -1;  // Index of the found element (-1 if not found)

// Struct for passing data to threads
typedef struct {
    int low;
    int high;
} SearchRange;

// Function executed by the thread
void *binary_search_thread(void *arg) {
 …</description>
    </item>
    <item rdf:about="https://medjava.ro/doku.php?id=c:pthreads:hello-world&amp;rev=1735842138&amp;do=diff">
        <dc:format>text/html</dc:format>
        <dc:date>2025-01-02T18:22:18+00:00</dc:date>
        <dc:creator>Anonymous (anonymous@undisclosed.example.com)</dc:creator>
        <title>hello-world</title>
        <link>https://medjava.ro/doku.php?id=c:pthreads:hello-world&amp;rev=1735842138&amp;do=diff</link>
        <description>Pthreads Hello World


#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;pthread.h&gt;

// This function will be executed by each thread
void *print_hello_world(void *tid) {
    // Print the thread&#039;s ID and a message
    printf(&quot;Hello World! Thread ID: %ld\n&quot;, (long)tid);
    pthread_exit(NULL);  // Exit the thread
}

int main(int argc, char *argv[]) {
    pthread_t threads[5]; // Array to store thread IDs
    int status;           // For storing return value of pthread_create
    long i;           …</description>
    </item>
    <item rdf:about="https://medjava.ro/doku.php?id=c:pthreads:makefile&amp;rev=1735842138&amp;do=diff">
        <dc:format>text/html</dc:format>
        <dc:date>2025-01-02T18:22:18+00:00</dc:date>
        <dc:creator>Anonymous (anonymous@undisclosed.example.com)</dc:creator>
        <title>makefile</title>
        <link>https://medjava.ro/doku.php?id=c:pthreads:makefile&amp;rev=1735842138&amp;do=diff</link>
        <description>Makefile to compile a pthread app in C


# Target for building the program
build: hello

# Rule for building the &#039;hello&#039; executable from &#039;hello.c&#039;
hello: hello.c
	gcc hello.c -o hello -lpthread

# Phony target for cleaning up
.PHONY: clean
clean:
	rm -f hello</description>
    </item>
    <item rdf:about="https://medjava.ro/doku.php?id=c:pthreads:merge-sort-parallel&amp;rev=1735842138&amp;do=diff">
        <dc:format>text/html</dc:format>
        <dc:date>2025-01-02T18:22:18+00:00</dc:date>
        <dc:creator>Anonymous (anonymous@undisclosed.example.com)</dc:creator>
        <title>merge-sort-parallel</title>
        <link>https://medjava.ro/doku.php?id=c:pthreads:merge-sort-parallel&amp;rev=1735842138&amp;do=diff</link>
        <description>Merge Sort Using Pthreads


#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;pthread.h&gt;

#define ARRAY_SIZE 8  // Size of the array
#define NUM_THREADS 2  // Number of threads

int array[ARRAY_SIZE];

// Struct for passing data to threads
typedef struct {
    int low;
    int high;
} SortRange;

// Function to merge two halves of an array
void merge(int low, int mid, int high) {
    int n1 = mid - low + 1;
    int n2 = high - mid;
    int left[n1], right[n2];

    // Copy data to temp arrays lef…</description>
    </item>
    <item rdf:about="https://medjava.ro/doku.php?id=c:pthreads:mutex-barrier-array-sum&amp;rev=1735842138&amp;do=diff">
        <dc:format>text/html</dc:format>
        <dc:date>2025-01-02T18:22:18+00:00</dc:date>
        <dc:creator>Anonymous (anonymous@undisclosed.example.com)</dc:creator>
        <title>mutex-barrier-array-sum</title>
        <link>https://medjava.ro/doku.php?id=c:pthreads:mutex-barrier-array-sum&amp;rev=1735842138&amp;do=diff</link>
        <description>Compute the sum of an array elements in parallel using pthread with mutex and barrier


#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;pthread.h&gt;

#define NUM_THREADS 4  // Number of threads
#define ARRAY_SIZE 100  // Size of the array

int array[ARRAY_SIZE];
int total_sum = 0;
pthread_mutex_t sum_mutex;
pthread_barrier_t sum_barrier;

// Function for each thread to compute part of the sum
void *partial_sum(void *arg) {
    int thread_part = *(int*)arg;
    int local_sum = 0;

    // Calculate…</description>
    </item>
    <item rdf:about="https://medjava.ro/doku.php?id=c:pthreads:mutex-shared-variable&amp;rev=1735842138&amp;do=diff">
        <dc:format>text/html</dc:format>
        <dc:date>2025-01-02T18:22:18+00:00</dc:date>
        <dc:creator>Anonymous (anonymous@undisclosed.example.com)</dc:creator>
        <title>mutex-shared-variable</title>
        <link>https://medjava.ro/doku.php?id=c:pthreads:mutex-shared-variable&amp;rev=1735842138&amp;do=diff</link>
        <description>Using mutex in pthread to access a shared variable


#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;pthread.h&gt;

// Global variable and mutex
int shared_variable = 0;
pthread_mutex_t mutex;

// Function to be executed by threads
void *update_shared_variable(void *arg) {
    pthread_mutex_lock(&amp;mutex);   // Lock the access to the variable
    shared_variable++;           // Update the shared variable
    printf(&quot;Updated value: %d\n&quot;, shared_variable);
    pthread_mutex_unlock(&amp;mutex); // Unlock …</description>
    </item>
    <item rdf:about="https://medjava.ro/doku.php?id=c:pthreads:parallel-increment-vector&amp;rev=1735842138&amp;do=diff">
        <dc:format>text/html</dc:format>
        <dc:date>2025-01-02T18:22:18+00:00</dc:date>
        <dc:creator>Anonymous (anonymous@undisclosed.example.com)</dc:creator>
        <title>parallel-increment-vector</title>
        <link>https://medjava.ro/doku.php?id=c:pthreads:parallel-increment-vector&amp;rev=1735842138&amp;do=diff</link>
        <description>Increment elements of a vector in parallel using pthreads

Parallelize the incrementing of elements in a 100-element array. This will involve dividing the addition iteration among all threads in the most equitable way possible.


#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;pthread.h&gt;

#define NUM_THREADS 4  // Number of threads to use
#define VECTOR_SIZE 100  // Size of the array

// Structure to pass information to threads
typedef struct {
    int start;  // Starting index for this thread
…</description>
    </item>
</rdf:RDF>
