NAME
pthread_rwlock_wrlock, pthread_rwlock_trywrlock - lock a read-write lock object for writing
...
The pthread_rwlock_wrlock() and pthread_rwlock_trywrlock() functions may fail if:
...
[EDEADLK]
The current thread already owns the read-write lock for writing or reading.
< /code>
Wenn ich jedoch den folgenden Code ausführe: < /p>
#include
#include
#include
#include
#include
int main()
{
int error;
pthread_rwlock_t *mutex = (pthread_rwlock_t *)malloc(sizeof(pthread_rwlock_t));
if (mutex == NULL) {
perror("malloc");
abort();
}
pthread_rwlockattr_t attr;
error = pthread_rwlockattr_init(&attr);
if (error != 0)
{
fprintf(stderr, "%s:%d: pthread_rwlockattr_init failed: %s", __FILE__, __LINE__, strerror(error));
abort();
}
error = pthread_rwlock_init(mutex, &attr);
if (error != 0)
{
fprintf(stderr, "%s:%d: pthread_rwlock_init failed: %s", __FILE__, __LINE__, strerror(error));
abort();
}
error = pthread_rwlock_wrlock(mutex);
if (error != 0)
{
fprintf(stderr, "%s:%d: pthread_rwlock_wrlock failed: %s", __FILE__, __LINE__, strerror(error));
abort();
}
error = pthread_rwlock_rdlock(mutex);
if (error != 0)
{
fprintf(stderr, "%s:%d: pthread_rwlock_rdlock failed: %s", __FILE__, __LINE__, strerror(error));
abort();
}
return 0;
}
< /code>
Die Ausgabe ist: < /p>
main.c:53: pthread_rwlock_rdlock failed: Resource deadlock avoided
< /code>
Aber wenn ich den folgenden Code ausführe: < /p>
#include
#include
#include
#include
#include
int main()
{
int error;
pthread_rwlock_t *mutex = (pthread_rwlock_t *)malloc(sizeof(pthread_rwlock_t));
if (mutex == NULL) {
perror("malloc");
abort();
}
pthread_rwlockattr_t attr;
error = pthread_rwlockattr_init(&attr);
if (error != 0)
{
fprintf(stderr, "%s:%d: pthread_rwlockattr_init failed: %s", __FILE__, __LINE__, strerror(error));
abort();
}
error = pthread_rwlock_init(mutex, &attr);
if (error != 0)
{
fprintf(stderr, "%s:%d: pthread_rwlock_init failed: %s", __FILE__, __LINE__, strerror(error));
abort();
}
error = pthread_rwlock_rdlock(mutex);
if (error != 0)
{
fprintf(stderr, "%s:%d: pthread_rwlock_rdlock failed: %s", __FILE__, __LINE__, strerror(error));
abort();
}
error = pthread_rwlock_wrlock(mutex);
if (error != 0)
{
fprintf(stderr, "%s:%d: pthread_rwlock_wrlock failed: %s", __FILE__, __LINE__, strerror(error));
abort();
}
return 0;
}
In diesem Fall gibt der Aufruf von pThread_rwlock_wlock edeadlk nicht zurück und blockiert stattdessen. Es scheint vernünftiger, dass Edeadlk zurückgegeben wird. Was könnte hier das Problem sein? Dies scheint eher ein häufiges Implementierungsproblem als ein für mein Setup spezifischer Problem zu sein. Ist dieses Verhalten beabsichtigt?
In der Dokumentation bei Open Group heißt es: < /p> [code]NAME pthread_rwlock_wrlock, pthread_rwlock_trywrlock - lock a read-write lock object for writing
...
The pthread_rwlock_wrlock() and pthread_rwlock_trywrlock() functions may fail if:
...
[EDEADLK] The current thread already owns the read-write lock for writing or reading. < /code> Wenn ich jedoch den folgenden Code ausführe: < /p> #include #include #include #include #include
return 0; } [/code] In diesem Fall gibt der Aufruf von pThread_rwlock_wlock edeadlk nicht zurück und blockiert stattdessen. Es scheint vernünftiger, dass Edeadlk zurückgegeben wird. Was könnte hier das [url=viewtopic.php?t=20324]Problem[/url] sein? Dies scheint eher ein häufiges Implementierungsproblem als ein für mein Setup spezifischer [url=viewtopic.php?t=20324]Problem[/url] zu sein. Ist dieses Verhalten beabsichtigt?
pthread_cond_wait( ) kann verwendet werden, um die Mutex-Sperre aufzuheben.
void call1(void *args){
pthread_mutex_lock(&mutex);
pthread_cond_wait(&cond,&mutex);
sleep(2);
cout
In meiner Anwendung erlaube ich Benutzern, wiederholte lokale Benachrichtigungen zu planen. Das Problem, das ich jedoch habe (von vielen anderen, die sich umschauen), ist, dass NextTiggerDate () den...
Ich nehme am Amazon Junior Dev-Kurs auf Coursera teil und arbeite mich durch das Abschlussprojekt des ersten Kurses, das sich auf Vererbung und Polymorphismus konzentriert.
Die umfassendere Aufgabe...