A New Collection of Thoughtful Learning Apps — Now Available on iOS & Android

Image
I’m excited to share a set of mobile apps I’ve recently completed and published on both the Google Play Store and the Apple App Store. These apps are designed with a simple goal in mind: to make meaningful, structured content more accessible, whether you’re studying theology or improving your English vocabulary. 📱 Now Available on Both Platforms All apps are live and available for download: Google Play Developer Page: https://play.google.com/store/apps/dev?id=5835943159853189043 Apple App Store Developer Page: https://apps.apple.com/ca/developer/q-z-l-corp/id1888794100 📖 Theology & Confession Study Apps For those interested in Reformed theology and classical Christian teachings, I’ve developed a series of apps that present foundational texts in a clean, focused reading format: The Belgic Confession Canons of Dort Heidelberg Catechism Westminster Shorter Catechism Each app is designed to provide a distraction-free experience, making it easier to read, reflect, and revisit these im...

Can pthread_mutex_lock still work after pthread mutex_destroy ?

Refer:
https://linux.die.net/man/3/pthread_mutex_init
The pthread_mutex_destroy() function shall destroy the mutex object referenced by mutex; the mutex object becomes, in effect, uninitialized. An implementation may cause pthread_mutex_destroy() to set the object referenced by mutex to an invalid value. A destroyed mutex object can be reinitialized using pthread_mutex_init(); the results of otherwise referencing the object after it has been destroyed are undefined.
What is the undefined behavior ?
Let's us wirte sample codes to verify it.
#include <pthread.h>
#include <iostream>
#include <unistd.h>

using namespace std;

static pthread_mutex_t foo_mutex;

static void *
thread1(void *arg)
{
   while(1) {
       pthread_mutex_lock(&foo_mutex);
       cout << "thread 1 running" << endl;
       sleep(2);
   }
}

static void *
thread2(void *arg)
{
   while(1) {
       pthread_mutex_lock(&foo_mutex);
       cout << "thread 2 running" << endl;
       sleep(2);
   }
}

int main()
{
    pthread_mutex_init(&foo_mutex, NULL);
    pthread_mutex_destroy(&foo_mutex);
    pthread_t p1;
    pthread_t p2;
    pthread_create(&p1, 0, thread1, 0);
    pthread_create(&p2, 0, thread2, 0);

    pthread_join(p1, 0);
    pthread_join(p2, 0);

    return 0;
}
~$ g++ -o pmt pmt.cpp -lpthread
~$ ./pmt
thread 1 runningthread 2 running
thread 2 running
thread 1 running
thread 2 running
thread 1 running
thread 2 running
thread 1 running
......
The result is NOT WORK ANY MORE.

❤️ Support This Blog


If this post helped you, you can support my writing with a small donation. Thank you for reading.


Comments